For years, Java has claimed type safety, but left variables out of the inheritance party. A new JDK Enhancement Proposal from Alex Buckley and Mark Reinhold aims to fix this problem in the language itself. There is, however, no timeframe for this addition to the Java language yet.
JEP 286 is officially titled Local-Variable Type Inference. The proposal would allow developers to elide manifest declaration of local variable types, keeping static type safety in place while easing the overall development process.
(Related: What’s to be expected in OpenJDK 9)
Buckley and Reinhold propose to “extend type inferences to declarations of local variables with initializers.” There have been efforts to bring similar functionality into Java in the past, but all have appeared outside the language itself.
One popular way of bringing type inference down to the variable level was created in Groovy’s == operator, but that function was removed from later versions of the language. Another popular method was to use Project Lombok, an open-source project that brings many language features to Java.
While JEP 286 is not approved for inclusion into any specific future release of Java, the fact that it was created by Reinhold, who is Oracle’s chief architect for the Java platform, is a good sign that it could appear as early as OpenJDK 9.
Also confirmed this week was that Project Jigsaw, an effort to modernize Java, will be released in OpenJDK 9.