Search

Categories

Links

Referers

Java SE 7 wish list

Dec 15 2006, 12:00:00 PM PST »Java»Language Comments [89]

With JDK 6 released, we are considering features for inclusion in JDK 7. Here is a list of things I would like to see (in no particular order):

Real closures
Neal has written a lot on this topic and I support his efforts. See Closures for Java (v0.3).
Type literals
Another (minor) proposal from Neal is type literals. See Super Type Tokens and Type Literals.
Super packages
This was originally suggested by Gilad Bracha, see Developing Modules for Development and JSR 294.
Improved type inference
Using generic methods can be hard if you do not understand how inference works. In particular, why does something like this not compile:
String s1 = Collections.max(Collections.emptySet());
String s2 = Collections.max((Set<String>)Collections.emptySet());
Most developers are not familiar with implicit type arguments but you have to use them when inference fails:
String s = Collections.max(Collections.<String>emptySet());
The original GJ compiler (which was the foundation for adding generics) did better. However, the specification was found to lead to an unsound type system and we did not find an alternative specification we had confidence in. I would like to investigate if we can do better now that we have more experience.
Shorthand syntax for declaring local variables
Most people familiar with either JavaScript or C# would like to have some feature that allows the compiler to guess the type of local variables. It has been proposed to add a new keyword (var) for this purpose. I would prefer not adding a new keyword as this can break a lot of existing programs. I discussed this with Christian Plesner Hansen on his last visit to Mountain View. He had a very simple solution that I really like:
final strings = new ArrayList<String>();
Christian's solution implies that you cannot assign the variable more than once. However, the more I think about this, the more I like it. We do not need to add a new keyword and if you don't want to specify the type of a variable, you should probably not assign to it later.
James Gosling suggested using := for declaring local variables without specifying the type. One way or the other, I think the language would benefit from having a shorthand.
Shorthand syntax for declaring properties
final property String name = "Name";
property String address;
becomes
final private String name = "Name";
public String getName() { return name; }
private String address;
public String getAddress() { return address; }
public void setAddress(String address) { this.address = address; }
Notice that property need not be a keyword.
Type aliasing
A while back, Gilad and I came up with this:
import java.util.List<String> as StringList;
Notice that as need not be a keyword.
Array syntax for collections
How sweet is this:
final map = new HashMap<String, Integer>();
map["one"] = 1;
More factory methods for collection classes
We have too few factory methods in the collection classes so you can write:
ArrayList<String> strings = ArrayList.of("a", "b", "c");
Self-types
I have mentioned self-types before.
Improved compiler diagnostics
Many diagnostics of javac are confusing, especially to new users:
String s = 1;
This gives this error message:
Test.java:3: incompatible types
found   : int
required: java.lang.String
        String s = 1;
                   ^
1 error
This would be better:
Test.java:3: attempt to assign an expression of type int
to a variable with an incompatible type (java.lang.String)
        String s = 1;
        ^^^^^^^^^^^^

Things I do not Wish for

Strings in switch statements
I would not mind seeing more types accepted in switch statements but I do not care that much for this.
XML literals
I would not like to see specialized XML-literals or multi-line strings but it would be interesting to examine if we can come up with a general syntax for many kinds of literals, including XML, SQL queries, RegExps, and XPath. But then again, I do not really care too much for this.
Shorthand syntax for accessing properties
You cannot overload '.' (dot) to mean property access because it would create strange rules (what happens if you have a field foo and a method getFoo()?) and be confusing. (is it field access or a method call with potential unknown side-effects?) On the other hand, it has to be '.' (dot). Anything else would look silly. I think this is unsolvable.
Post a Comment:
Comments are closed for this entry.
Comments:

What are your arguments against multiline String literals? For most code it makes sense to embed small (say 5 lines max) "foreign languages" (like SQL queries) as a final variable or class constants. The current approach really uglifies code by adding a plethora of quotes, + concatenations and character escapes. It makes support for nested language lexers in IDEs a bit harder too...

Posted by Taras Tielkes on December 15, 2006 at 12:44 PM PST #

I would rather see a general solution for embedding foreign languages than hacks like multi-line strings or narrowly scoped features such as XML literals.

Posted by Peter von der Ahé on December 15, 2006 at 12:57 PM PST #

I agree on almost all counts (both wish and do not wish). "final" is a more natural choice for type inference.

String switch statements would just encourage more use of strings which we do not need. XML literals are insane.

Consider this entry shared.

Posted by Bob Lee on December 15, 2006 at 01:57 PM PST #

I am concerned.

Maybe I'm an old stick in the mud or something but one of the things that has made me keep coming back to Java is that the code is nice and readable. Compare any Java program to Perl or C or almost any other language and I think most people would agree that the Java one is easier to follow. Why? A nice straightforward syntax. Not a lot of keywords. No pointers. In short, it's because of all the things that Java didn't do that made the language so readable. So it concerns me that we adding all these new shiny baubles to the language without considering what it will do to the long-term maintainability of the code, the readability that makes it so nice to work with etc.

I would far rather that you focused on the usability of the existing Java APIs, on adding new APIs like NIO2 that keeps getting delayed, improved memory usage and performance.

Please remember that every time you add a feature to the language that (unless you're very careful) you're reducing the readability of the code that will be eventually written.

I think the original designers of the language did a very good job of balancing features vs. readability etc... It concerns me that the people that are now in charge of the language aren't considering this so much. All the closure proposals I've seen seem to involve ugly syntax to the language. Shorthand syntax for local variable assignment? A new assignment operator (:=) ... Ugh. IMHO, it's not worth it. Please. Don't clutter up the language. Don't turn it into Perl where there are at least 49 ways to express the same thing.

Thanks,
Corey

Posted by Corey Puffalt on December 15, 2006 at 06:28 PM PST #

Corey, somehow your comment got flagged as spam. Sorry about that.

This is my personal wish list. I do not decide what actually happens. But since everybody else are public about what they want, I felt I had to make my preferences known as well.

I'm a compiler engineer and I implement language features and the purpose is to make existing API easier to use. But that has nothing to do with NIO2. But speaking of it, I'm convinced that the new NIO2 guy will get something done.

BTW: I find your comment about ':=' very funny given that it was suggested by James Gosling.

Posted by Peter von der Ahé on December 15, 2006 at 08:10 PM PST #

About shorhand syntax for accessing properties, I have had a look at http://www.weiqigao.com/blog/2006/12/07/you_wont_believe_this_but_the_arrow_operator_is_coming_to_java_7.html I love the idea to use new arrow operator instead of plain old dot one. However, I see the line a->Foo = b->Foo; I think that it will introduce a Sun's Java coding convention conflict.

Posted by pcdinh on December 15, 2006 at 11:28 PM PST #

Things like a->Foo is what makes me really dislike proposals for property access.

Posted by Peter von der Ahé on December 16, 2006 at 07:44 AM PST #

Just coming back to Groovy to see how it use dot operator to access properties in a Map aMap.(propertyName) I dont know why Java Team does not like this syntax. I guess that there is a technical obstacle to this approach.

Posted by pcdinh on December 17, 2006 at 01:32 AM PST #

My wishlist: Writing JavaBean in Java 5.0, 6.0 is a tedious and time-consuming task. It would be great if Java 7.0 support a official way to make it more productive and fun by using annotation: class User { @Property private int userId; @Property (getter=getUserName, setter=setUserName) private String userName; }

Posted by pcdinh on December 17, 2006 at 02:03 AM PST #

Multi-line strings would really simplify reading xml, sql, etc... It would be nice to have a shorthand syntax for map elements. Type aliasing could provoke a producing more literals that would make to read and understand java programs more difficult.

Posted by Igor Katrayev on December 17, 2006 at 03:25 PM PST #

Hi Peter Nice list. It is a bit ironic to see C++ typedefs proposed for Java 7!! I personally dont like the arrow operator for property access, I prefer the C#-style property keyword - I think its much cleaner and more consistent. Agreed on the array-style syntax for collections - another long standing C++ feature. And the Collections/Array classes could certainly do with a few more convenience factory methods! PS Its incredibly hard to post a comment on this blog :-(

Posted by Rory Winston on December 18, 2006 at 02:17 AM PST #

Hi everybody, i've patched javac to provide a prototype that allows the syntaxes decribed by James Gosling and Christian Plesner Hansen for declaring local variables.

The prototype is downlodable on my blog.

Let me know what you thinking.

Rémi

Posted by Rémi Forax on December 18, 2006 at 03:01 AM PST #

Rory, something has changed in regards to spam settings. Everything seems to get caught and I have manually remove the spam-bit from many comments all of a sudden.

Posted by Peter von der Ahé on December 18, 2006 at 03:12 AM PST #

I am in broad agreement with you about additions that would be beneficial to Java and a while back blogged about Clear, Consistent, and Concise Syntax . The blog suggests syntax like:

  • withLock lock, method{out.println "Hello"}; // Note no brackets and method{} for a closure
  • declare sum = 0; // Integer, for int use: int sum = 0 or declare int sum = 0
  • final strings = ArrayList< String >.new.add "A"; // Note Type.new instead of new Type for backward compatibility
  • method toString { "Hello" } // Overridden method declaration with return inferred
  • new( i ) { default } // Constructor uses new and infer argument type from field of same name and default means copy of argument into field - ML like but more flexible
  • method getName { default } // Read access to a variable of name Name - similarly setName
  • Plus some shortening and improved consistency for generic declarations

The point of this syntax is, as the name suggests, to be Clear, Consistent, and Concise (in that order). In particular the syntax uses

keyword( ... ) { ... }
to be consistent with other Java constructs like
if
, etc.

The C3S syntax presented in the blog referenced above comes from earlier attempts, notably RFE 6389769 and a previous blog. In both these cases I consistently got feedback that the essence of Java is clear and consistent syntax that uses keywords. Hence the C3S proposal.

What do people in this forum think?

PS Sorry about the blocks - it was the only way I could get a code like font on the blog!

Posted by Howard Lovatt on December 18, 2006 at 05:51 PM PST #

Closure - not really. Feels like too much overlapping with other features in the language, even though it could make other things possible. IMO a language should stay concise, i.e. minimising the number of ways to accomplish any given task.

Type Literal - quite cool from completeness point of view.

Super packages - will need to see how it gets on with existing visibility mechanism. One can't erase history in the Java Language ;-)

Improved Type Inference - yeah, why not? I like the challenge from an academic point of view as well.

Shorthand syntax for declaring local variables - "final" is definitely an elegant solution. Especially that means the keyword would get used more often, hence could save me a lot of trouble when debugging / fixing others' code!

Shorthand syntax for declaring properties - I think Tools is the answer to this, not the language itself.

Type aliasing - could potentially becomes as confusing as #define. And it's probably just me but I really quite like the verbosity - just get yourself a bigger / wider screen :-D

Array syntax for collections - nice, but not very Java-ish to me and would make the language less "concise".

More factory methods for collection classes - or constructors? Can be decided through a popularity vote I suppose.

Self-types - hmmm... I don't have any compelling use cases off the top of my head. So I shall kindly skip this one :-P

Improved compiler diagnostics - always a nice & ongoing work.

Strings in switch statements - ugh, go away! *takes deep breathe* I mean, what are the gains beside introducing another possibility to do the same thing?

XML literals - indeed embedding these stuff outside the Java source code, e.g. through property files with IDEs' aid seem to be the better way.

Shorthand syntax for accessing properties - can't really see what we can gain from this. Really.

Posted by Alex Lam on December 21, 2006 at 12:04 AM PST #

marked as spam?!

Posted by Alex Lam on December 21, 2006 at 12:05 AM PST #

Closure - not really. Feels like too much overlapping with other features in the language, even though it could make other things possible. IMO a language should stay concise, i.e. minimising the number of ways to accomplish any given task.

Type Literal - quite cool from completeness point of view.

Super packages - will need to see how it gets on with existing visibility mechanism. One can't erase history in the Java Language ;-)

Improved Type Inference - yeah, why not? I like the challenge from an academic point of view as well.

Shorthand syntax for declaring local variables - "final" is definitely an elegant solution. Especially that means the keyword would get used more often, hence could save me a lot of trouble when debugging / fixing others' code!

Shorthand syntax for declaring properties - I think Tools is the answer to this, not the language itself.

Type aliasing - could potentially becomes as confusing as #define. And it's probably just me but I really quite like the verbosity - just get yourself a bigger / wider screen :-D

Array syntax for collections - nice, but not very Java-ish to me and would make the language less "concise".

More factory methods for collection classes - or constructors? Can be decided through a popularity vote I suppose.

Self-types - hmmm... I don't have any compelling use cases off the top of my head. So I shall kindly skip this one :-P

Improved compiler diagnostics - always a nice & ongoing work.

Strings in switch statements - ugh, go away! *takes deep breathe* I mean, what are the gains beside introducing another possibility to do the same thing?

XML literals - indeed embedding these stuff outside the Java source code, e.g. through property files with IDEs' aid seem to be the better way.

Shorthand syntax for accessing properties - can't really see what we can gain from this. Really.

Posted by Alex Lam on December 21, 2006 at 12:06 AM PST #

Alright, alright - spam I am then.

Closure - not really. Feels like too much overlapping with other features in the language, even though it could make other things possible. IMO a language should stay concise, i.e. minimising the number of ways to accomplish any given task.

Type Literal - quite cool from completeness point of view.

Posted by Alex Lam on December 21, 2006 at 12:13 AM PST #

Super packages - will need to see how it gets on with existing visibility mechanism. One can't erase history in the Java Language ;-)

Improved Type Inference - yeah, why not? I like the challenge from an academic point of view as well.

Posted by Alex Lam on December 21, 2006 at 12:14 AM PST #

Improved Type Inference - yeah, why not? I like the challenge from an academic point of view as well.

Shorthand syntax for declaring local variables - "final" is definitely an elegant solution. Especially that means the keyword would get used more often, hence could save me a lot of trouble when debugging / fixing others' code!

Posted by Alex Lam on December 21, 2006 at 12:14 AM PST #

(Comments on super packages marked as spam. Oh well...)

Shorthand syntax for declaring properties - I think Tools is the answer to this, not the language itself.

Type aliasing - could potentially becomes as confusing as #define. And it's probably just me but I really quite like the verbosity - just get yourself a bigger / wider screen :-D

Posted by Alex Lam on December 21, 2006 at 12:15 AM PST #

Array syntax for collections - nice, but not very Java-ish to me and would make the language less "concise".

More factory methods for collection classes - or constructors? Can be decided through a popularity vote I suppose.

Posted by Alex Lam on December 21, 2006 at 12:16 AM PST #

Self-types - hmmm... I don't have any compelling use cases off the top of my head. So I shall kindly skip this one :-P

Improved compiler diagnostics - always a nice & ongoing work.

Strings in switch statements - ugh, go away! *takes deep breathe* I mean, what are the gains beside introducing another possibility to do the same thing?

XML literals - indeed embedding these stuff outside the Java source code, e.g. through property files with IDEs' aid seem to be the better way.

Shorthand syntax for accessing properties - can't really see what we can gain from this. Really.

Posted by Alex Lam on December 21, 2006 at 12:16 AM PST #

I noted that you listed JSR 294 on your wish list, but not JSR 277. Why one and not the other? While you don't like strings in switch statements, how about ranges, e.g., 2 .. 10: rather than 2: 3: 4: 5: 6: 7: 8: 9: 10:? This is a shorthand that would seem to improve readability rather than detract from it.

Posted by Scott Richmond on December 21, 2006 at 01:00 AM PST #

IMHO, I don't like most of these ideas. Java's beauty is its simplicity, which will be messed up by more and more language features. Untyped language might has a lot of power, but to meantain and understand others codes are much more difficult.

Posted by tcmaster on December 21, 2006 at 05:46 AM PST #

About the "Shorthand syntax for declaring properties"... I don't see the point of that syntax. The whole point of "get" and "set" is to allow for encapsulation of extra processing around property access. For example, a "setter" can validate input, persist data or whatever. A "getter" can provide access to a computed property (suppose "width" and "height" are real properties, there's no point in defining a third "area" property when you can define "getArea" as a value based on width and height). All your example buys is more long-winded way to type "get" and "set"... It's preferable to do something like: private String f; public String property foo { get { return f; } set throws IllegalArgumentException { check(value); f = value; } } ... where "value" is the unique value of the property's type passed to the setter. The declaration of indexed properties could be as follows: private List<String> values; public String property foo[i] { get { if (i < 0 || i > values.size()) throw new IndexOutOfBoundsException(...); return f[i]; } set throws IllegalArgumentException, { if (i < 0 || i > values.size()) throw new IndexOutOfBoundsException(...); check(value); values.set(i,value); } } As for "array syntax for collections", maybe this is better: @ArrayAccess public V get(K key) { // implemented here } ...so that it can be generalized beyond the Map interface. - Chris

Posted by Christopher Brown on December 22, 2006 at 05:40 AM PST #

About the "Shorthand syntax for declaring properties"...

I don't see the point of that syntax. The whole point of "get" and "set" is to allow for encapsulation of extra processing around property access. For example, a "setter" can validate input, persist data or whatever. A "getter" can provide access to a computed property (suppose "width" and "height" are real properties, there's no point in defining a third "area" property when you can define "getArea" as a value based on width and height). All your example buys is more long-winded way to type "get" and "set"...

It's preferable to do something like:

private String f;

public String property foo {
 get {
  return f;
 }
 set throws IllegalArgumentException {
  check(value);
  f = value;
 }
}

... where "value" is the unique value of the property's type passed to the setter. The declaration of indexed properties could be as follows:

private List<String> values;

public String property foo[i] {
 get {
  if (i < 0 || i > values.size()) throw new IndexOutOfBoundsException(...);
  return f[i];
 }
 set throws IllegalArgumentException,  {
  if (i < 0 || i > values.size()) throw new IndexOutOfBoundsException(...);
  check(value);
  values.set(i,value);
 }
}

As for "array syntax for collections", maybe this is better:

@ArrayAccess
public V get(K key) {
 // implemented here
}

...so that it can be generalized beyond the Map interface.

- Chris

Posted by Christopher Brown on December 22, 2006 at 05:43 AM PST #

What about including the eclipse SWT into the jre and jdk. So we could use that toolkit to develop and distribute these types of applications without the overhead of having to make our clients download the SWT toolkit. It would also make pease with the people over at the eclipse foundation.

Posted by Christopher Stura on December 22, 2006 at 06:21 AM PST #

Here is another though what about the wonderfull #ifndef and other macro's available to C/C++ programmers. I wonder how many people would like to see a way to keep compatibility with multiple java versions using a single code base. I have to solve a problem now with a legacy J2EE 1.4 application which I have to develop and maintain on 1.4 for a few clients, however I would like to use J2EE 5.0 to develop new code and now have to somehow split up my code base to make this work. I would like a #ifndef type of think like #ifndef _J2EE_5 @Annotation1 #endif that would make my J2EE 1.4 just ignore that. It would also be nice to include directives like. #ifndef _J2EE_5 #exclude <some java file> #endif or write a bunch of nifty macro's #define TOINT(Integer.valueOf(<String>var)) nice isn't it?

Posted by Christopher Stura on December 22, 2006 at 06:26 AM PST #

Shorthand syntax for declaring local variables is retarded. It is very easy and more readable to provide the damn type. We don't need shorthand for properties, we also don't need array syntax for collections. All these things make reading code more difficult. I for one do not want the language to turn into something that is not readable (ie Perl). Having only a few ways to accomplish the same task improves readability and makes it easier for people to learn Java.

Posted by 65.220.16.193 on December 22, 2006 at 06:29 AM PST #

Peter:

>> I would rather see a general solution for embedding foreign languages than hacks like multi-line strings or narrowly scoped features such as XML literals.

I'd started the lexicalj project about a year ago, wherein I used a preprocessor to embed a language within java that would allow closures in 1.5. Obviously, Neal's proposals take all of the wind out of the sails of that idea, but I wonder if something like the proposed syntax would meet your definition.

Posted by David Hall on December 22, 2006 at 06:41 AM PST #

I'm very much against the shorthand for local variables. I see very little value in it. It stinks of the crud that makes Visual Basic as bad as it is. Shorthand for declaring properties is not needed either. Annotations should be able to handle this easily and allow for fancy customizations such as handling PropertyChangeSupport in the setters. The "improved" compiler error message is only slightly better - and even then only for English users. The original error message is very clear to begin with so I'm not sure how the effort is justified in tweaking it further. I'm not sure why any Object type should not be allowed in a switch, with each case using the "equals" method to evaluate the switch.

Posted by SWP on December 22, 2006 at 06:43 AM PST #

This blog worries me because I really dont like these "improvements", especially shorthand syntax. I want my code to say exactly what it means, to be clear and consise. Is the problem just that it takes too long to type? This is what I hate about C#, which unfortunately is my day job, the language is full of so much CRAP. I love Java because it is minimalist, without all the extra nonsense as the others, but just as powerful. Why properties? We always say hide your fields, use getters and setters. If properties become the same thing, then whats the point? well, because you can override them right. You can override them because they're methods. So why hide the fact that they are methods? It becomes two different ways of writing the same thing, and this is bad! Plus, the JavaBeans property syntax comes in useful when I'm using my IDE, I can type .get, hit control space, and only the list of properties i can get. With C#, nope, all I get is one long list with every property, event, and method on the object. Same with ".add" for listeners, and especially useful for ".is" when i know the property is boolean. Dont get rid of this! Many of the JDK5 improvements I do think were a good thing, like generics, because the type checking improves the quality of the product. But shorthand doesnt. And I'm more interested in the quality of my software than how quickly I can type it, or pleasing on the eyes it is. Things like closures are just going to confuse your average Joe Developer and so actually might reduce the quality of our software! One I might support, is the ability to define aliases in imports. Yeah for generics, but also like distinguishing between java.util.Date and java.sql.Date, which happens all the time. At the end of the day, changes like these to language arent going to make our software any better. The language is fine. We should be focussing on improving the APIs instead. Oh but if you can improve the compiler diagnostic messages, go for it! Now that's an idea!

Posted by Ben Loud on December 22, 2006 at 08:17 AM PST #

I see a suggestion above about including SWT. Please no. Improve AWT instead.. if it's even worth it to do that. Swing works and works well. All the reasons for SWT to exist are long gone. Let it die, or if you must have native widgets, put the effort into a better AWT. We don't need a third option here.

Posted by SWP on December 22, 2006 at 08:38 AM PST #

- Java "package" (s) are similar to C++ "namespace" (s) or delphi "unit" (s). But, In delphi, "superpackage" (s) have a special syntax called "package" ;-)

Posted by mramirez on December 22, 2006 at 09:17 AM PST #

Here is my not-fully-compatible take on properties and Java. Note that my comment there on Groovy is now outdated (and even was at the time of my statement).

Posted by Tom Palmer on December 22, 2006 at 11:32 AM PST #

I'm a little disturbed by all the latest comments about "bla bla bla don't add anything". The idea of adding some of these things, like shorthand syntax for declaring local variables, *should* also make reading the code clearer by reducing the amount of redundant information that you have to type in the code. Now - there are some things, like the closure syntax, that I don't like because I think it makes the language harder to read. But the idea of making the common things we do all the time shorter and just as easy to read (*cough* property access *cough*) is a very good idea. I especially disagree with comments that say array syntax for collections is bad - could it *be* any *easier* to figure out? I'm all for it. I'd also like to see (as mentioned) an easy way to create a collection of values like "new ArrayList(1, 2, 3, 6)" or something. I do this *all* the time. I have more thoughts, but I'll end my comment here.

Posted by WillGayther on December 22, 2006 at 02:04 PM PST #

I hope to see some thing similar to the linq project in C#3 or .NET hope you guys to participate at the sun form on this topic http://forums.java.net/jive/thread.jspa?threadID=21183&tstart=0 also there is new idea for operator overloading http://forums.java.net/jive/thread.jspa?threadID=21349&tstart=0 one more thing for my wishes for java please involve arraylist generics to deal with primitives types int, long, double because I am sick of it

Posted by rami on December 22, 2006 at 02:57 PM PST #

In my opinion (doing more far software maintenance than green-fields development these days) the "Shorthand syntax for declaring local variables" means a maintenance engineer has to figure out the *actual* return type of assignment expression. If the assignment is somewhere down the code from the declaration he also has to go searching to find it. Bad, bad, bad, bad, bad! It might be nice for the original code writer to have tyhis feature, and as Alex Lam says it might be a nice academic exercise, but my experience says it will be a pain in the jaxx for people reviewing and maintaining the code. Also, I know you don't like strings as cases in switch statements (too simple to be interesting?) but to me this is the only feature worth adding as it is certain to get used heavily in real software. At the moment everyone has to deal with a large cascades of if-then-else of strings in their programs. I agree with Corey. Simplicity in the language and complexity in the libraries is what makes Java great. Keep things simple as not every Java programmer bothers to read the web to learn new stuff, but we depend on these less capable guys to get out projects done (or we don't make money). I suggest we follow Einstein and keep it, "As simple as possible, but no simpler". By the way. Since I've never commented directly to you before Peter, thanks for all your hard work on the compiler and language. In my opinion Java is light years ahead of the C# as it solves practical problems rather than fashionable ones.

Posted by Mike Reid on December 22, 2006 at 05:56 PM PST #

How about adding namespaces in the imports, something like in XML? This will help to simplify the code when dealing with different packages that provide classes with the same names. If we imagine that the import statement could be modified to accept an optional prefix that the developer could choose, just like with the XML namespaecs. We could do:
import util:java.util.List;
import awt:java.awt.List;

class WidgetFactory {
 awt:List createLabel(util:List<String> labels) {
   awt:List widget = new awt:List(4, false);

   for (String label : labels) {
     widget.add(label);
   }
   
   return widget;
 }
}

Posted by Emmanuel Rodriguez on December 22, 2006 at 11:31 PM PST #

How about the option of reference counted garbage collection for reliable finalization?

Posted by Neil Swingler on December 22, 2006 at 11:38 PM PST #

Please for the love of God don't implement Type aliasing! This 'feature' seems like a horrible idea. We don't need yet *another* layer of indirection.

Posted by Michael McCutcheon on December 22, 2006 at 11:45 PM PST #

The more I look at it, most of these 'improvements' are completely unnecessary. I don't want something to save me typing. That is never the problem. As others have mentioned, it's about quality, not quantity. Please don't add stupid 'features' to the language that save typing or make yet another way of doing something that is already easy.

Posted by Michael McCutcheon on December 23, 2006 at 12:06 AM PST #

Properties: What became of the syntax of "->" to denote a property access? I don't care for syntax enhancement that are disguised preprocessor commands. Properties should be allowed in interfaces - the expansion above will not work Type Aliasing: Back to C? This looks like "typedef" and creates the same problems: You look at a trivial piece of code and spend 90% of the time to understand the locally defined types; just the opposite would be more useful: import com.mycompany.SimpleList implements java.util.ArrayList; to import both and shadow the implementation of ArrayList so that any use of ArrayList would be compiled as a reference to ArrayList without refactoring.

Posted by Carsten on December 23, 2006 at 04:24 AM PST #

I would also like to see Shorthand syntax for ArrayList like #("a", "b", "c");

Posted by hiren on December 23, 2006 at 06:08 AM PST #

I don't like a single thing in your wish list.. they are all horrible ideas for Java (maybe not for another language). Multi-line literals would be nice.. and strings in switch statements seem like better ideas.

Posted by dog on December 23, 2006 at 09:31 AM PST #

Everyone have their own decision, someone like multi-line literal, someone like the -> accessor (even -> look ungly, but I think tis is a proper way rescuses java from getter/setter hell and gets the correct way to handle properties), someone like XML literal ( should be someone, VB guys ? I dun hear much objection from VB guys about VB9) ...etc Somone said String-switch sucks( I think so, should use enum instead), Someone said String-switch can help them to replace the if-elseif pattern. Anyway, I know you guys from Sun/Java Community can do a great job to improve Java. Thank you for the great job and Merry X'mas ~~~

Posted by Francis on December 23, 2006 at 11:20 AM PST #

Let's ruin the language some more by turning it into RubyPerlyC--.

Posted by Jeroen Wenting on December 24, 2006 at 12:37 AM PST #

Hi Peter,
I disagree with most of your proposals, as they don't make Java development nor maintenance easier. (And maintenance being the most important area. Although, we all love to do the new stuff ;-)

Let's take short hand notations: As nobody types all this declaration code anyway, it's no big win. IDEs do all that for me.
The point is: is it better to read? I don't think so. Code has to explain itself, as documentation is outdated anyway it most cases. So, making it unnecessary to define types, write certain keywords, ... makes it harder, as one has to know all those conventions.

Closures: I don't see the advantage in cluttering Java with a new syntax. I agree, that anonymous inner classes are ugly. But it's a good thing, as they are only used when it's really needed ;-)
Closures don't make code more readable. They don't offer enough advantages to justify the hassle.

Instead of making Java easier, let's make it more powerful and let the IDE do the hard work of defining all that stuff (as it's done with the current features).

For Java 7, I'd prefer to see modularization of the class library, clean-up of old deprecated methods, continued retrofitting of Generics in the 'old' APIs (especially those int constants usd all over Swing&Co.

Just my 0.02$,
Claus

Posted by claus on December 24, 2006 at 01:22 AM PST #

Something always strikes me when the Java community is discussing the language - what you want to see included and excluded from a language is largely based upon the area you work in. The majority of the Java in the world is server-side, so the largest vocal element in the debate are server developers - client application developers and specialist areas like numerical applications (physical simulation, games, biotech) don't make as much noise. Does that mean they shouldn't get what they want simply because Java found a niche in servers to start with? Is that really how you think the platform should evolve into the future? If Java has no more room for improvement, why are other languages still being used for new projects?

Posted by Andy L on December 24, 2006 at 04:08 AM PST #

The key to efficiency is to promote stuff to syntax, and then optimise what goes on behind that syntax so that it no longer uses the method imposed by the original syntax which is less efficient. Example: we know that iterators aren't really that efficient (objects created, etc), so why use objects as the backend behind this, knowing that all we want to do is go over the elements of a list?

Posted by Chris Dennett on December 24, 2006 at 09:15 AM PST #

I agree with some of the sentiment already expressed; specifically, providing multiple ways to express the same thing--despite the syntactic simplicity of an alternate--tends to reduce maintainability, which is often the largest cost of a software system during its lifecycle. Reducing maintainability is likely to make Java less attractive as a language over time.

I'd also like to suggest an additional item for your consideration, type-level interface methods.

Posted by Nathan D. Ryan on December 24, 2006 at 10:25 PM PST #

why the "property" and "as" not a keywork? It should be keyword if you use as it. instead we can using @Property which need not to be a keyword. Also, I think XML literal is a good things, or we can support a more general syntax like @XML("xml-literal-which can span more lines"), and you can also extend like @SQL. We can define such an extension mechanism, and make Java language more "Domain Language" like. eg, we can define as @LiteralBuilder(XMLLiteralBuilder.class) public @interface XML { String value(); } the XMLLiteralBuilder is response to build the result object during javac compile time.

Posted by wangzx on December 25, 2006 at 06:41 PM PST #

Dear Santa, I hope none of the changes that complicate the type system (and make Java difficult to learn for a newbie) go in. I sincerely hope Java doesn't become victim to the experiments of a few language experts. I'm genuinely worried about it; we're heading the C++ way by getting into a mindless arms race with C#. The power of the language lies in its simplicity. Don't kill it.

Posted by Bharath R on December 26, 2006 at 02:17 AM PST #

Strings in switch statements
I would not mind seeing more types accepted in switch statements but I do not care that much for this.


Well Peter, I would certainly appreciate a feature like this, maybe through an syntax addition to the switch statement itself. Examples:

switch (value)
{
  case (1)
  {
    // a single int (same as the current behavior,
    // but without the need of a break statement.)
  }
  case (2, 3, 4)
  {
    // an array of int containing { 2, 3, 4 }.
  }
  default
  {
    // ...
  }
}

switch (value)
  case ("one")
  {
    // same thing with a String.
  }
  case ("two", "three", "four")
  {
    // similar, with an array of Strings.
  }
  default
  {
    // ...
  }
}

Posted by Jerome on December 27, 2006 at 05:42 AM PST #

I would like multiple finally statements allowed. in the form: try{ }catch(Exception e){ }finally{ }finally{ }//etc this would allows multiple critical statements to be executed without interfering with each other. Though I don't know what would happen when multiple exceptions are thrown...

Posted by Lucas Jordan on December 27, 2006 at 06:38 AM PST #

I agree with Bharath R on "Dear Santa, I hope none of the changes that complicate the type system (and make Java difficult to learn for a newbie) go in. I sincerely hope Java doesn't become victim to the experiments of a few language experts. I'm genuinely worried about it; we're heading the C++ way by getting into a mindless arms race with C#. The power of the language lies in its simplicity. Don't kill it."

Lot of this could be achieved by IDE's and external libs. Don't push this ideas in JDK, please keep the simplicity alive and clean up the jdk and fix performance bugs. Better yet provide a way to implement compiler & runtime extensions.... So people can share there ideas in plugin form rather then pushing it all out in JDK and pushing simplicity away from the language....

Posted by Pratik Parikh on December 27, 2006 at 08:10 AM PST #

As one who writes Java code to access embedded systems I'd like to see unsigned versions of all of the integer types (byte, short, integer, etc.).

Posted by Herb Poppe on December 27, 2006 at 03:16 PM PST #

Oh no. Please, please, please do not add any of these. Are you aware of the caliber of the average "engineer" we real-world programmers have to work with on a daily basis? Please think of the effect you're going to have on the international business community before you change what has become the lingua franca of programming.

Posted by Laird Nelson on December 27, 2006 at 04:08 PM PST #

I wish:
  • Shorthand syntax for declaring local variables (using auto?)
  • Shorthand syntax for declaring properties (please!)
  • Array syntax for collections
  • More factory methods for collection classes
  • Multi-line string (and XML?) literals
  • Shorthand syntax for accessing properties (but it very well be unsolvable...)
And no for:
  • Strings in switch statement

Posted by A. Reader on December 27, 2006 at 08:25 PM PST #

I disagree with: The power of the language lies in its simplicity. Don't kill it. and Instead of making Java easier, let's make it more powerful and let the IDE do the hard work of defining all that stuff.

I, for one, like to write my code. Shorthand syntax for declaring properties helps. A lot.

Posted by A. Reader on December 27, 2006 at 08:36 PM PST #

Every Language should be support Design by Contract. Project like Contract4J etc, are good, Language support should be better.

Posted by asd on December 28, 2006 at 05:00 AM PST #

An example, Java Design By Contract Language Support class Example{ public void method{ pre: lablel: expression // expression (contains visible features) //code post: lablel : expression // expression (contains "old values", this // feature needs deep_copy) } invariant label:expression } class ExampleInherit extend Example{ public void method{ pre: lablel: expression // expression (contains visible features) //code post: lablel : expression // expression (contains "old values", this // feature needs deep_copy) } invariant label:expression } preconditions: or (ed) postconditions: and (ed) invariants: and (ed)

Posted by asd on December 28, 2006 at 05:09 AM PST #

I like the property suggestion. While this particular idea may need to be refined, I definitely think it is an idea worth developing.

My primary motivation for a feature such as this is to increase the level of documentation because I am frustrated by requiring to javadoc the field, the getter, and the setter. When writing classes, I generally start with defining the private fields, then will use Eclipse to generate the public getters and setters. I like to Javadoc each field, but that Javadoc then needs to be repeated two more times (get and set), so I end up with needing to maintain 3 copies of the documentation. Trying to keep documentation up to date is hard enough -- let alone maintaining multiple copies.

I do agree that sometimes there is value to defining an explicit getter or setter, so that ability needs to be preserved (also for backwards compatibility), but 90% of the time a standard shell is sufficient.

I have posted some ideas about this already:

Parameter validation is a valid concern for setters. Personally, I like the Hibernate Validator annotations approach. Maybe that idea also needs to be built into the language. (The JPA includes some validation rules like nullability, and length, but this is not as sophisticated to validate regular expression matching, minimum and maximum numeric ranges, or anything more sophisticated.)

Posted by Anthony Whitford on December 28, 2006 at 07:16 AM PST #

Your "Array syntax for collections" (map["one"] = 1;) is a limited form of operator overloading.

I'm all in favour of operator overloading, because the arguments in favour are powerful (e.g. doing things like Complex arithmetic is absurdly clunky using method calls); and the arguments against always seem specious to me (e.g. "C++ operator overloading lets you shoot yourself in the foot"), because they usually assume that Java's implementation would have to be like other languages.

As it happens, I'm not in favour of using [] for maps, because I think a[n] should be shorthand for a.get(n), and a[n] = b should be shorthand for a.set(n,b). Basically I think there should be some interfaces in java.lang whose methods are aliases for specific operators. For instance, java.lang.Storage could define E get(int index) and E set(int index,E element). Any class that implements it can use [] syntax instead of these methods; so java.util.List would extend java.lang.Storage. Storage would have a written contract, like any other interface: it would say that get(n) returns the same object previously stored via set(n). Bye bye C++ operator abuse nightmares.

Similar interfaces could be defined to allow, but control, the overloading of +, - etc. For instance it might be required that (a+b-b).equals(a).

Posted by Jonathan on December 28, 2006 at 11:22 AM PST #

groovy like string value assignment to the block of text: String text = """ hello! how are you today? """

Posted by Seyyed Jamaleddin Pishvayi on December 28, 2006 at 10:19 PM PST #

I think what we have to add to java is a language-level feature as a compiler switch in the class declaration. So the gurus can use their JDK 8.5beta and this will well work together with closures, etc.

It is true that most Java programmers don't read blogs like this and never dared to comment here. So no fancy stuff: Java is not Ruby nor C - and it is chosen to be the platform for large projects for that reason.

Closures are a border-line case: (the syntax of) Anonymous classes are so ugly that few developers can stand using them, on the other hand the rebrand of closures from functional feature to abstactraction for flow control provoked a lot of complications that will deter many programmers from using closure - now for a different reason than they despise anon classes.

I programmed a bit of Scala in the last week - I went back to declaring vars and vals fully because I found my own (experimental) code hard to read ... so simply leave simplyfied declarations. It is like having all as Object and the compiler guessing which cast to insert... Java has no coercion like JavaScript and C# - so this feature is again a macro for the 12 programmers that still use vi to develop Java.
Yes, I want to have the Scala views - type conversion in Java is poorly developed and is a major obstacle for the reuse of components.

PS: Are properties "non-OO"?

Posted by Carsten on December 28, 2006 at 11:46 PM PST #

* Real closures Sure, if the syntax is clean enough. Something a little more readable than the anonymous inner classes we use now. * Type literals Sure, for completeness' sake. * Super packages Yes, but not necessarily in the Dolphin release. Let's make sure the JCP get this fleshed out first. If it's done in time for Dolphin, fine. Otherwise no. * Improved type inference Not yet. Let's get used to having generics before we change it. * Shorthand syntax for declaring local variables No. Completely pointless, adds nothing of value and detracts in maintainability. * Shorthand syntax for declaring properties No. Make it an annotation for the boilerplate case that you want a getter and setter that do nothing but get and set and allow overriding of the implicit methods. But not this. * Type aliasing NO!!!! * Array syntax for collections I can live without it. No need to incorporate the class library into the language any further. * More factory methods for collection classes Not for me, but go ahead. * Self-types Maybe. * Improved compiler diagnostics That's nice -- but what does it have to do with the LANGUAGE SPECIFICATION? * Strings in switch statements No. Object orientation usually offers better solutions to switch statements. * XML literals No. What would be the difference with a String literal? And why overspecialize the language? What will be the point of an XML type in the language when Web Services lose their popularity? * Shorthand syntax for accessing properties No.

Posted by Ben Tels on December 29, 2006 at 05:43 AM PST #

I just want to get away from the getter/setter hell... Dun u guys think using setter/getter is a waste of life... I saw some funny posts: 1) "The power of the language lies in its simplicity." Shorthand to delcare and acess the property offer more simplicity. also it will be follow the DRY principle 2) "Are you aware of the caliber of the average "engineer" we real-world programmers" there is not enginner called "average" just some called "UNPropessional" If ur engineers don't learn, no doubt they will be let behide in the fast evolution natural of IT. If the new syntax is designed easy to learn, U can't have any reason to reject it. em... just bcuz u is refuse to learn ??? 3) "So the gurus can use their JDK 8.5beta and this will well work together with closures, " OMG, Use ur brain to learn man, new things can't hard if u learn. Ur reply look like some High school cerf. Programmer in my company. Stupid, Not willing to learn and reject to any changes. These post mademe think of the days that "Professional Java programmers" want to add delete and remove GC from java. Sun added GC and bytecode to Java, and manay people said Java is suck . Now, everyone agreed that Sun did the right thing. --- OUT-Of-Trend, Out-Dated, Short-Sighted mind !!! Comeon Peter, Try ur best, dun lose to these no brainers.

Posted by M on December 30, 2006 at 11:43 AM PST #

One more thing, Annotation is not supposed to chnage the Language, It is not code generator or someone else that allow u to create getter/setter.

Posted by M on December 30, 2006 at 11:46 AM PST #

Peter, I'm mostly concerned with how the proposed features would interact with IDE workflow. Please find my comments below. Type aliasing: please design this feature in such a way that aliased type is mentioned in every file, i.e. alising is local to a file. Breaking this property would result in IDEs unable to use inverted files to index aliased class occurrences, and consequently result in slowdown when working with IDE. Import is OK in this regard, though I would rather prefer explicit typedef on file level (New keyword here could be easily handled by context lexer) to continue importing classes rather than types. Shorthand syntax for declaring local variables: here I like the variant proposed by Christian, as well as Neal's suggestion for inferencing type arguments of new expression. The latter suits well when the variable of parameterized class type is first declared, in this case one first gives the full type information in variable type, and then uses the IDE to complete concrete class in "new" not duplicating type arguments. The former is good for introducing variable from part of existing code when the IDE can ensure expected variable type can be inferred from initializer. Also note that the IDE could easily point the programmer the declared type of the variable/make it explicit if he needs it. Shorthand syntax for declaring properties: I don't think this needs to be implemented taking into account the automation of property methods' generation in all IDEs. Array syntax for collections/maps: though having this does not hurt, is it all about saving four characters for writing ".get" or ".set"? Improved type inference: you could at least consider inferencing from expected argument type for method call argument if the method is unambiguous.

Posted by Eugene Vigdorchik on December 30, 2006 at 12:07 PM PST #

M:<em>One more thing, Annotation is not supposed to chnage the Language, It is not code generator or someone else that allow u to create getter/setter.</em>

No, annotations are not supposed to change the language -- they're supposed to add metadata to a program, which may then mean something to language processors like the compiler.

At the same time, the JavaBeans Specification (JavaBeans Spec) defines a property as a named attribute that will always be accessed through accessor methods (see chapter 7). Which means that if something in a class is a property, that class will publish a getter or a setter for that thing.

Given that, I see absolutely no problem in introducing an annotation that defines a property and therefore implicitly introduces a getter and setter into a class definition. Obviously it won't do much for you if you want a derived property, but most properties people define are just the boilerplate case. And you can certainly save typing in that case.

For example, one might consider the following annotations:

  @Property
  private Color color; /* A regular, "boilerplate" property */
  @Property(read-only="true")
  private PersonnelNumber number; /* Only exposes a getter */
  @Property(write-only="true")
  private int somethingElse; /* Only exposes a setter */

One might also consider listener associations, but I'd have more reservations about that. Something like this:

  @Property(vetoableChangeListeners="my.package.Listener0,my.package.Listener1")
  private String blah;
  @Property(propertyChangeListeners="my.package.Listener2,my.package.Listener3")
  private String boo;

Posted by Ben Tels on December 31, 2006 at 06:47 AM PST #

Test...

Posted by Jonathan on January 01, 2007 at 11:46 AM PST #

Sorry, but it seems that any way I phrase my important comment ;^) it gets marked as spam and isn't posted. Any tips anyone?

Posted by Jonathan on January 01, 2007 at 11:54 AM PST #

Hi, There are two features which I would like to have integrated in Java. One is real-closures and the second is a concept known in Objective-C as Categories. Regarding real-closures I agree all arguments given in favour of that feature. In order to explain best the "categories" concept I will quote wikipedia. START Quotation: Categories Cox's main concern was the maintainability of large code bases. Experience from the structured programming world had shown that one of the main ways to improve code was to break it down into smaller pieces. Objective-C added the concept of Categories to help with this process. A category collects method implementations into separate files. The programmer can place groups of related methods into a category to make them more readable. For instance, one could create a "SpellChecking" category "on" the String object, collecting all of the methods related to spell checking into a single place. Furthermore, the methods within a category are added to a class at runtime. Thus, categories permit the programmer to add methods to an existing class without the need to recompile that class or even have access to its source code. For example, if the system you are supplied with does not contain a spell checker in its String implementation, you can add it without modifying the String source code. Methods within categories become indistinguishable from the methods in a class when the program is run. A category has full access to all of the instance variables within the class, including private variables. Categories provide an elegant solution to the fragile base class problem for methods. If you declare a method in a category with the same method signature as an existing method in a class, the category's method is adopted. Thus categories can not only add methods to a class, but also replace existing methods. This feature can be used to fix bugs in other classes by rewriting their methods, or to cause a global change to a class's behavior within a program. If two categories have methods with the same method signature, it is undefined which category's method is adopted. Other languages have attempted to add this feature in a variety of ways. TOM took the Objective-C system a step further and allowed for the addition of variables as well. Other languages have instead used prototype oriented solutions, the most notable being Self. END Quotation Well, we all know that some part of the JRE is well designed and other not. This concept would help to improve the framework. Furthermore we implement a lot of utility classes in order to provide that funtionality which is not supported by classes of the JRE. Categories is an elegant way to extend given Types without changing their identiy. E.g the String class would remain teh String class but with improved functionality. I have work as an software developer using objective-c for a long time and can confirm that this feature comes with great flexibility and elegance. bye

Posted by Juan Carlos Flores Beltran on January 01, 2007 at 12:24 PM PST #

@Ben Tels.

Ur idea is very innovative, but sorry it is not a good one.
Since annotation is not per-processor or some code generator,
I read that somewhere in Danny's and Peter's blog, sorry I can't find it back
so this code:
@Property(xxxxx)
private int m;
can't generate a getM() and setM(xxx) for u..
At least not atsource level.

if u write something like this.

class Foo {
@Property(i just want a getter)
private int uCannotGetMe;
}

//somewhere:
Foo f = new Foo();
f.getUCannotGetMe();

well, obviously during ur code writing the method getUCannotGetMe() is not existing, so at compile time a method not found error will be caught.

Of course, u can change the compiler, but it is not worth.

Think about the way that how the annotation was hanlded in EoD features of JDBC4.0 and JPA, u will know why @Property can't generate a getter/setter for u...

Posted by Mm on January 01, 2007 at 01:18 PM PST #

Jonathan, I have to manually correct the spam filter :-(

Unfortunately, I seem to have deleted your comment starting with "'Array syntax for collections' is a form of operator overloading" so please post it again.

Posted by Peter von der Ahé on January 01, 2007 at 03:41 PM PST #

@Mm

Why should it be necessary to change the code at source level? Annotating a field with @Property would simply mean that the class in question defines a property of that name and type and would therefore imply the presence of a getter and/or setter -- an annotation is only as much as how the tools interpret it to be, after all. It seems to me that code generation in the source would defeat the point of using an annotation.

And perhaps the JCP would decide that such an annotation is not worth the effort. Still I'd be opposed to the property shorthand as an alternative.

Posted by Ben Tels on January 02, 2007 at 01:19 AM PST #

Eugene,

No need to worry about IDE integration, the compiler team is very focused on that aspect.

Cheers,
Peter

Posted by Peter von der Ahé on January 02, 2007 at 06:42 AM PST #

Peter, Thank you for making it clear, that compiler team realizes the unique position of java, that it has the greatest tooling support among all languages. I'm really looking forward to working on making new language features most productive in all aspects. Eugene.

Posted by 195.177.121.231 on January 02, 2007 at 07:51 AM PST #

'Array syntax for collections' is a form of operator overloading. This kind of notation is clearly good for collections, and would be even more useful if generalized. It seems to me that the argument always given against adding operator overloading to Java is 'operators in C++ are widely abused' - but that's because C++ leaves them open to abuse. Java needn't implement them in the same way.

IMHO a simple and safe operator overloading system would be to allow certain operators to be aliases for methods: a[b] would be converted to a.get(b), a[b] = c converted to a.set(b,c), etc. But to protect them from abuse, the conversions only work for classes which implement a corresponding special interface: for instance, if a class implements java.lang.Storage (containing get and set) then it's allowed to use the two forms of the [] operator. The protection from abuse is given by the contracts for these methods. They could specify, say, that get(n) must retrieve the value v previously passed to set(n,v).

This is how arithmetic operators like +, -, * and / can be restricted to behave in 'number-like' fashion for classes like Point and Complex. Their contracts would be based on algebraic rings and fields, which are the usual generalizations of arithmetic used in mathematics. Ironically, this would leave the built-in + operator for String as the only one that abuses the system! (Since I expect the contract for addition would require that (a + b - b).equals(a).)

A system like this seems very simple but powerful, and could easily be retrofitted to existing classes in the JDK.

Posted by Jonathan on January 03, 2007 at 05:13 AM PST #

I am sorry that you are so negative about native property support. Property boilerplate is extremely verbose, and it would be a true blessing to have it tamed. Whether or not to use the arrow operator seems an exceedingly minor detail--see http://weblogs.java.net/blog/cayhorstmann/archive/2007/01/arrows_in_the_b.html

Posted by Cay Horstmann on January 07, 2007 at 03:38 PM PST #

I've often found myself wanting to return a set of values from a function, and have to resort to some awkward use of an array or a class solely for the purpose of holding those values. So something like:
public (double, double, double) getGpsCoordinates() {
   ...
   return (x, y, z);
}

main() {
   double x, y, z;
   (x, y, z) = getRoots(1.0, 1.0);
}
And maybe even treating the "tuple" syntax as a quick way of creating a new kind of anonymous classe quickly:
public (double a, double b, long c) getGpsCoordinates() {
   ...
   return (x, y, z);
}

main() {
   // here we treat the tuple as a type
   (double p, double q, long r) myCoordinates;
   myCoordinates = getRoots(1.0, 1.0);
   System.out.println("Your coordinates: ");
   System.out.println(" 1: " + myCoordinates.p);
   System.out.println(" 2: " + myCoordinates.q);
   System.out.println(" 3: " + myCoordinates.r);
}
Haven't thought much more about it, though, so this may in fact be a very bad idea. :-)

Posted by CR on January 10, 2007 at 07:00 AM PST #

Don't Make Java HotchPot like c#.

Posted by X on January 20, 2007 at 12:42 PM PST #

I would very much like to see operator overloading in Java (see Neils blog for operator overloading ideas) but also the ability to define in a class operator as methods. For instance in Scala one can do: class A{ def ! (msg : String):Unit = { /// do something } } this combined with the infix form invocation: ... val a = new A a ! "a message" // "!" is just a method ... so Scala uses this aproach for actors and obtain the same style as Erlang actors. I know that A LOT of people hate operator overloading from C++ but then again one has always the option to not use it. It's all about increasing the expressivness of the language.

Posted by Marius on January 25, 2007 at 06:25 AM PST #

to keep it short.
i strongly agree with CR that there is a need for compound basictypes in order to keep java to be language of choice especially for scientific computing, multimedia and 3D graphics/gaming applications.

Compared to most of the other proposed features, the introduction of tuples would ease development and generally speed up high performance and low memory algorithms, since there is no other way to handle those problems equally (in java), that stack based compound basictypes would solve.

being forced using boxing for returning multiple values cripples most efficient algorithms by introducing costly memory allocations, where there should be no need for:

(double, double) complex[][] = fourierMatrix.transpose().toArray();
instead of
ComplexNumber complex[][] = ...

which implies a ComplexNumber allocation for every matrixcell, just to be able to hold two values in one cell

double real[][] = ...
double imaginary[][] = ...
which is the common workaround, splitting the values and messing up code.

java.awt.Polygon(int[] xpoints, int[] ypoints, int npoints)
double width = dimension.getWidth(), height = dimension.getHeight();
int temp=a; a=b; b=temp;
could be replaced by
java.awt.Polygon((int,int)[] points)
(double width, double height) = dimension.get();
(a,b) = (b,a);


Personally im pretty worried about watching many fellow students and game developers switching from java or c++ to c#, just because .net offers stack based compound basic types while java punishes that kind of algorithm design. The fact that worries me, is that the topic feels not being dealt with as compared to other language beautifications, that actually do not improve any essential java aspect.
(crap this comment isnt short at all)

sounds interesting? check
http://www.cs.vu.nl/.../reeuwijk-jgi2002-tuples.pdf

Posted by Philipp on February 10, 2007 at 04:06 AM PST #

Good list of new features. A very big new feature I'd like to see is open source development of se7 for Mac OS X. I find that the delay of availability of new releases by Apple hampers the platform independence of java. For example, is SE6 platform independent? Not for OS X, because it's still effectively not available -- all that's available is a 7 month old "preview". (Worse, Apple declines to publicly provide java developers with any information whatsoever on their planned timetable for releases.) In my view, SE7 would be the right place to start this work.

Posted by Scott Cotton on April 08, 2007 at 08:20 AM PDT #

I think the better solution then super packages is visibiliy per class e.g

class Controler{

View Model getModel(){}

Controler void setParent(Controler controler){}

}

getModel() can access only instances of View and subclasses. It allows only for correct framework use.

Posted by TW on April 11, 2007 at 05:23 AM PDT #

There is one feature for the Java language/compiler I'd really like to see: something like a "nullable" / "notnull" reasoning.

Generics help us to avoid the annoying runtime ClassCastExceptions by having the compiler find code that isn't type-safe before runtime. Similar, the "notnull" reasoning would have the compiler check for potential NullPointerExceptions.

I'm not sure how much of this reasoning can be automated - maybe it doesn't need the help from any new keywords. And there are compatibility questions - what about code that really wants to get NullPointerExceptions?

Posted by Ralf Kleberhoff on May 04, 2007 at 01:46 AM PDT #