Local-variable type inference with `var` makes it easier to work with anonymous classes, for example to create ad-hoc fields and methods. But does that mean you should use them more often? I think not.
With ‘var’ it is much easier to work with intersection types in Java 10 and later. You still need non-trivial tricks with generics to declare intersection types, but thanks to ‘var’ it is now easy to create local variables of such types.
On Java 10+, you can use application class-data sharing to reduce launch times, response time outliers, and memory footprint. By archiving class data with -Xshare:dump and loading it with -Xshare:on, the JVM’s class loading workload can be reduced considerably.
Java 10 introduces ‘var’ which lets the compiler infer local variable types. Here’s how it works, why it exists, and how it impacts readability.