Speculating about Java 7 Language Features

This morning at EclipseCon I attended a talk on Java 7 language features, given by Peter von der Ahe and Alex Buckley of Sun Microsystems.

The talk was quite speculative – naturally no decisions have yet been made about what will be in Java 7. However Peter and Alex’s predictions are probably a reasonable guide to the features that Sun will be championing, and what struck me most about their proposals was just how many are clearly inspired by features already present in C# version 2 and (in some cases) C# version 3.

Just to briefly run through the list, first of all we had a with block, to reduce the try {} finally {} boilerplate associated with using resources. The equivalent in C# is the using block. Next Alex talked about reification of generics – i.e. killing the demon of erasure that was created with Java 5’s implementation of generics. C# generics have always been carried through to the runtime, i.e. List<String> and List<Integer> are real separate classes. Admittedly they had less backwards compatibility constraints than Java did.

Next up were various bits of syntactic sugar, for example property syntax, XML literals (LINQ anybody?), array syntax for access to collections and maps, and even the suggestion of limited type inferrence, e.g. var m = new HashMap<String>() where the type of m can be easily inferred by the compiler.

I think that most of these ideas are pretty good. They don’t significantly increase the complexity of the Java language, in fact they make some of the most commonly repeated patterns more concise. Unfortunately they also talked about “super packages”, JSR 294 and JSR 277. The air was heavy with irony as Alex told an Eclipse and OSGi crowd that, in Java 7, they will be able to build modular applications and hide packages! Also the talk went on too long, leaving no time for questions. Come on Sun… you’re still not listening!