Thursday, April 10, 2008

My Java 7 wishlist

These are a few of my own ideas about what I think should be in Java 7. These are partly compiled from things I both like and hate about C# and other ideas borrowed from other languages and - at least as far as I know - some of my own ideas.

Also I will point out that I am not including closures or type inference or any other functional language stuff. Frankly this has been discussed ad-nauseam, however I will point out that I am absolutely for these features, all of them.

Here we go:

  • Delegates have never really been a hit with the Java folk. Lets keep it that way.

  • I can live with UnReified generics, but wildcards have gotta go.

  • Fix Autoboxing. In my opinion a job half done. I want to be able to write 1.toString() now!

  • Structs suck! James Gosling was right.

  • I like the idea of properties in Java, but only for binding purposes. basically I want to be able to bind to a fixed type safe Java construct as opposed to using a string to denote a property name.

  • While we're at it, lets add some shorthand notation for getters and setters.

  • Dynamic proxy support for abstract classes.

  • Inheritance for static members.

  • Dynamic invocation blocks. This is an idea for Java that I thought of around the time Rails was causing noise. Basically what this is, is the ability to dynamically handle method calls similar in the way that that Ruby or Smalltalk handle messages or method calls which are not actually implemented. By default an exception is thrown if the method does not actually exist, however the method which handles this can be overriden, as is the case with the ActiveRecord framework which uses this to do dynamic finders. There is no reason we couldn't have something similar in Java. Basically it would work like this: Interface and abstract methods no longer need to be implemented by concrete classes provided that the class implements an Interface similar to java.lang.reflect.InvocationHandler (which is used to do the same thing for dynamic proxies). The compiler could simply substitute the unimplemented method with the invoke method on the InvocationHandler. This would then be completely type safe and provides a similar level of guarantee to the caller as you would have implementing the method normally.

  • Bundle Groovy or JRuby as part of the JRE It's time for the JVM to strike out and provide alternatives. Admittedly groovy might be better, since it was designed with the Java API in mind and presents a bit less overhead.

  • A Range object.

  • Flesh out the String class with useful static utilities, those that inevitably end up in a StringUtils class which get rewritten for every project I've ever worked on like isEmpty() to determine if a string is null or empty.

    These beauty is that many of these features (except maybe for properties) require no new additions to the basic language structure and for the most part can use a bit of compiler magic and some new libraries.

    Let me know what you think.
  • No comments: