March 2019
Intermediate to advanced
242 pages
6h 21m
English
The following lines of code show how local variables (and all other variables) were defined prior to Java 10:
String name = "Java Everywhere"; LocalDateTime dateTime = new LocalDateTime.now();
Starting with Java 10, by using var, you can drop the mandatory explicit type in the declaration of local variables, as follows:
var name = "Java Everywhere"; // variable 'name' inferred as // String var dateTime = new LocalDateTime.now(); // var 'dateTime' inferred as // LocalDateTime
Does it look like the preceding code doesn't offer a lot of benefits? Imagine you could take the following code:
HashMap<Integer, String> map = new HashMap<Integer, String>();
And replace it with this code, instead:
var map = new HashMap<Integer, ...
Read now
Unlock full access