March 2019
Intermediate to advanced
242 pages
6h 21m
English
Using var doesn't imply just dropping the type of the local variable; what remains should enable the compiler to infer its type. Imagine a method that defines an array of the char type, as follows:
char name[] = {'S','t','r','i','n','g'};
You can't replace the data type name, that is, char, in the preceding code with var and define it using any of the following code samples:
var name[] = {'S','t','r','i','n','g'};
var[] name = {'S','t','r','i','n','g'};
var name = {'S','t','r','i','n','g'};
Here's one of the ways to include relevant information, so that the compiler can infer the type:
var name = new char[]{'S','t','r','i','n','g'};
It seems like the Java compiler is already struggling with this assumption from the programmers, ...
Read now
Unlock full access