Posts

Showing posts with the label Java10

Java 10 - Local Variable Type Inference

Java 10 - Local Variable Type Inference In one of my previous blog, I have already discussed about Type Inference. If you don’t have the idea about Type Inference then you can check my blog here . If we want to understand Type Inference in one line then we can say that It is the capability of the compiler to automatically detect the datatype of a variable at the compiler time. What is Local Variable type inference? Java 10 added new feature that allows the developer to skip the type declaration associated with local variables (those defined inside method definitions, initialization blocks, for-loops, and other blocks like if-else), and the type is inferred by the JDK. It will, then, be the job of the compiler to figure out the datatype of the variable. Until Java 9 , we had to define the type of the local variable. E.g.: String message = “Welcome to Waheedtechblog.com”; The above statement is right as that’s how things have been since the inception of java b...