+ 11
What’s new in Java 10?
Is here a lessons about java 10? Who knows or try?
9 odpowiedzi
+ 4
The two big stories in Java 10 are:
the new var keyword, just like you’d imagine with any new language construct, and
the new six-month release cycle
Also, developers will be excited to see more API evolution. And, there are runtime improvements, new performance tuning knobs, and the now-perennial garbage collection improvements that we’ve come to expect with each release.
But there are a number of other interesting things, too, especially if you know how to read in between the lines and look ahead to Java 11 in September.
Local Variable Type Inference
With the exception of assert from the Java 1.4 days, new keywords always seem to make a big splash, and var is no different.
Perhaps, the most curious thing about it is that it isn’t actually a reserved word, but something else entirely. But, there will be more on that in a moment.
What the var keyword does is turn local variable assignments...
HashMap<String, String> ughThisIsSoVerbose = new HashMap<>();
into:
var succinct = new HashMap<String, String>();
Added Readability
Simply put, as long as the construct on the right-hand side doesn’t require a target type on the left-hand side (like lambdas do), then, you can make all kinds of code easier to read, as shown below:
var tshirts = Lists.of("Baeldung Medium", "Java Large", "Lua Small");
var lines = Files.get(Paths.get("log/catalina.out"));
var length = lines.count();
Some Caveats
In other words, Java 10 introduces local-variable type inference to the language. At compile time, it figures out the reference type based on the value type.
Now, we can append this to the growing list of type inferences that Java makes, already including type inference with generics and with lambda expressions.
This feature has been a long time coming. It was suggested as far back as 2001 and was closed at that time with the following comment by Gilad Bracha.
Humans benefit from the redundancy of the type declaration in two ways. First, the redundant type serves as valuable docume
+ 2
Key improvements include local variable types as well as enhancements for garbage collection and compilation.
JDK 10 is scheduled to be just a short-term release, and public updates for JDK 10 are stated to end in six months. The upcoming JDK 11, due in September, will be a long-term support (LTS) version of Java. LTS releases are due every three years.
+ 1
Some people just learn differently. You need to find the way you like to learn and learn that way. Have fun coding 👍
0
ty both answers
0
the sololern find
0
type inference