Compulsory non-null initialization

A local variable defined with var must be initialized with its declaration, or the code won't compile. The compiler can't infer the type of an uninitialized variable or a variable that is assigned a null value. The following code won't compile:

var minAge;                   // uninitialized variable 
var age = null;               // variable assigned a null value  

The following image illustrates what would happen if the uninitialized variable age went to seek entrance to the Mr. Java compiler place. The compiler won't let age in:

Variable definition using var must always be accompanied by its initialization, or the code will fail to compile.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.34.62