Local-Variable Type Inference

As we have seen countless times in this book alone, when you declare a variable in Java, you have to declare the type twice, once on the left-hand and once on the right-hand side, plus a variable name:

    AtomicInteger atomicInt = new AtomicInteger(42); 

The problem here is that this code is verbose and repetitive. The Local-Variable Type Inference effort hopes to fix that, enabling something like this:

    var atomicInt = new AtomicInteger(42); 

This code is more concise, making it more readable. Notice the addition of the val keyword. Typically, the compiler knows that a line of code, for example, is a variable declaration when it sees <type> <name> = .... Since the effort would remove the need for a type on the ...

Get Java 9: Building Robust Modular Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.