Local Variable Type inference in Java 10

var age;
....
age = 24;
var str = "Java 10"; // infers String
var stream = list.stream(); // infers Stream<String>
var list = new ArrayList<String>(); // infers ArrayList<String>
var list = List.of(1, 2.0, "3");
var bos = new ByteArrayOutputStream();
try (Stream<Student> data = dbconn.executeQuery(sql)) {
return data.map(...)
.filter(...)
.findAny();
}
try (var data = dbconn.executeQuery(query)) {
return data.map(...)
.filter(...)
.findAny();
}
for(var s : arrList){
....
}
for(var i=0; i<str.length(); i++){
var ch = str.getCharAt(i);
}

--

--

Innovative software development professional. Loves sharing knowledge and learning latest stacks. Expertise in microservices architecture using spring boot.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Habeeb Okunade

Habeeb Okunade

19 Followers

Innovative software development professional. Loves sharing knowledge and learning latest stacks. Expertise in microservices architecture using spring boot.