|
SDN Chat Sessions Transcripts Index
April 26, 2005 This is a moderated forum. MDR-EdO: Welcome to today's SDN chat on New Language Features in J2SE 5.0. J2SE 5.0 includes the biggest set of language changes since the original release of the Java programming language. In today's chat, you'll have a chance to ask questions about these new language features and get answers from three key members of the Core Java team: Scott Seligman, Joe Darcy, and Peter von der Ahé. Our guests are ready for your questions, so fire away! JavaJim: What would you consider the 1 or 2 most important enhancements to the language, and why? Joe Darcy: The most significant change to the language was the introduction of generics, which allow you write programs that abstract over types. Another large change was annotations (metadata), which is intended to allow automation of boilerplate code. Krishna: One of the new features in J2SE 5.0 is class data sharing (CLS). How does it differ from MVM?
Joe Darcy: This is a bit outside our area of direct expertise, but here goes. Class data sharing allows precompiled portions of Krishna: The overriding methods are not the same as in previous versions. That is, the return type can be different if the return type of the method in the subclass has inherent relation with the superclass method's return type. Is there any specific reason for this change?
Scott Seligman: In earlier Java versions, an overriding method had to have the same return type as the overridden one. In 5.0, the overriding method is allowed to return a subtype of the overridden one's return type. Consider a class Tiger that is a subclass of Animal, each with a JavaJim: Don't you think that static imports tends to create a lot more verbosity in a program? I envision programs chock full of additional imports like this: import static classA.CONSTANT_A; import static classB.CONSTANT_B; import static classC.CONSTANT_C; ... Peter von der Ahé: You should be careful of using static imports too much as you hint they can make code harder read. Krishna: I came across many articles about the new features on Java 5.0. They mentioned only these:
Joe Darcy: They only mentioned those 7 items? That is a whole lot! Those are all the major changes. My pet change was the introduction of hexadecimal floating-point literals :-) steevcoco: Hi. What specific tasks can the APT currently perform for us? Joe Darcy: The apt tool is a general meta-programming tool; you can write processors that do arbitrary computations based on the program structure, including what annotations are present. JavaJim: Can enum types be subclassed? Scott Seligman: No, they can't (not explicitly, at any rate). Since enum constants are modeled as static fields in the enum type's class, the obvious implementation wouldn't do what's "expected". Switch statements would also become problematic, since multiple subclasses could potentially have the same enum constant name. Perhaps those issues could have been addressed somehow, but the complication was not considered worthwhile.
MrK: How do I get the maximum possible error detection from javac? Is that with
Peter von der Ahé: Yes, izuz: Any coding standard guidelines for annotations? If we have an annotated method (long annotation), with the annotation on a different line than the rest of signature, do we indent the annotation 4 spaces more than the method signature, or vice-versa, or something else?
Scott Seligman: We haven't published anything, though it would be a good idea once we have enough experience. We have sort of adopted our own informal guidelines. We put the annotations before other modifiers (
.
. @ALongAnnotation("...................")
. public void m() {
JavaJim: When will there be an update to the Language spec? Joe Darcy: A draft pdf of the new language specification is now online. The published version should be available in June. izuz: Can I use the enhanced for loop with genericized collections? Joe Darcy: No, the enhanced for loop works with non-generic arrays, including arrays of primitives; very handy! Krishna: Will autoboxing affect performance? Scott Seligman: Only if abused. Autoboxing is essentially just syntactic sugar for taking a primitive, say an int, wrapping it in a wrapper object such as an Integer, and then doing the reverse. The performance will be the same as doing this explicitly. Autoboxing does make it less obvious that this work is happening, though, so you need to be aware of what's going on. steevcoco: Are there prebuilt annotations in the APT?
Joe Darcy: Other than an implicit
MrK: Will there ever be a formal way to do conditional compilation or macro expansion in Java? (e.g. Scott Seligman: Not likely. LSantha: Could you tell us a bit about hexa float literals, like their purpose, examples, usefulness. This didn't get much publicity so far.
Joe Darcy: Hexadecimal floating-point literals, originally introduced in C99, are a way to avoid the vagaries of decimal -> binary conversion. This conversion is the source of much of the confusion related to floating-point; for example the literal "0.1" is not exactly representable in binary floating-point, instead you get a number very close to 0.1, with an error around 10^-17. So what you see isn't exactly what you get. For some applications, like math libraries and test programs, you really need to know exactly what bits end up in a floating-point value. The hexadecimal literals allow you to do this precisely without using the Krishna: What are all the new key words introduced in J2SE 5.0? Like assert is introduced in J2SE 1.4. Scott Seligman: "enum" is the only one. Adding new keywords causes major source compatibility headaches, so we do it only when it's absolutely essential. (I sure wish that the ":" in enhanced "for" loops could have been "in" instead.)
MrK: If I use the new 5.0 language features, can I use Joe Darcy: There is no supported way to do that; in general the new language features require libraries introduced in Tiger. bor: Is the performance of reflection impacted due to supporting Generic, Annotation, and enum type?
Scott Seligman: No. There are a bunch of new reflection methods, but the old ones work essentially the same as before. The methods that deal with generics explicitly (like
bskaarup: I do a lot of work with XML Often I have an
Scott Seligman: The object to be iterated over must simply be an Krishna: If you had to do it all over again, are there any language features that you would change? Joe Darcy: In brief, adding generics to Java was greatly constrained by compatibility requirements. Incorporating generics into a new language wouldn't have all those restrictions. There were discussions when Java was first being done about adding some kind of generics, but they didn't think they had time to work out all the details. Krishna: Are there any problems with using covariant return types in classes that might have subclasses? Peter von der Ahé: Well, you can't have covariant parameter types. As you hint, you should be careful when using covariant return types in classes that might have subclasses outside your control. However, it is perfectly safe to use this feature when designing new class and interface hierarchies. Krishna: Here comes Varargs. Will it affect the method overloading at any way?.
Scott Seligman: Generally, a vararg method acts just like its array-based counterpart (e.g: MrK: How can you tell what type the compiler infers?
Peter von der Ahé: A trick I often use is to make an intentional error. For example, if you have a method returning a
izuz: Scott Seligman: Sure, that's just fine. I use it myself. JavaJim: A lot of users are moving to the Mac. Do you know when Apple will implement JDK 5.0 on the Mac? Peter von der Ahé: Not really sure, I understand they are pretty close. krish: Do you have any other major language features that you plan to introduce in version 6 or later? Peter von der Ahé: No new language features for Java SE 6. We are considering what to do for Java SE 7 (the following release). A lot of people are asking for better XML support, friends (like C++), and typedefs/aliasing.
krish: The class 'Class' now takes a template argument so that methods like
Scott Seligman: For clone, backward compatibility is the reason. Pre-existing subclasses have clone methods that return krish: Couldn't you have used class tokens to know collection's element type at runtime? Was serialization compatibility a reason for not doing this?
Scott Seligman: You can have collections that are constructed with type tokens (see some of the izuz: How can I write my 1.4 library so that 5.0 users can use varargs when calling its methods? Scott Seligman: The 5.0 user needs to compile against a vararg version of the method, so this doesn't work as you'd like. MDR-EdO: Well, we've quickly come to the end of our session. I'd like to thank everyone who participated today. We had a nice range of questions. And of course, I'd especially like to thank our guests Scott, Joe, and Peter for their answers. Scott Seligman: Thanks for all your questions and interest! Joe Darcy: Good bye! We'll have some JavaOne sessions on generics and annotation processing, as well as some bofs on the same. You can ask more questions on generic types in the generics forum on java.sun.com. MDR-EdO: Moderator signing off. The forum is now unmoderated. | ||||
|
| ||||||||||||