This is a memo for organizing Java Silver study ...
--Appeared from SE10 --Type inference of local variables --Data type is inferred according to the value on the right side
var v1 = "hoge"; //Treated as a String
var v2 = 123; //Treated as an int
--Because it is variable type inference, ** declaration only ** cannot be done-> because type inference cannot be done without assigning a value --Therefore, ** null assignment is not possible **
var v3; //This is a compile error
var v4 = "huga"; //ok
var v5 = null; //This is also a compile error
--Cannot declare multiple variables
int i1 = 1, i2 = 2, i3 = 3; //ok
var v6 = 6, v7 = 7, v8 = 8; //Compile error
--Cannot be used as a method formal argument type
String piyo(var val){
...
//Compile error
}
Recommended Posts