新版本的变更 / Java 10

// var is only for a local variable with an initializer:

// var x;                       // <- error: no type to infer from
// var y = null;                // <- error: null alone says nothing
// var[] arr = { 1, 2, 3 };     // <- error: no var arrays
// var nums = { 1, 2, 3 };      // <- error: an array initializer needs a type

class Point {
    // var field = 1;           // <- error: not for fields
    // int sum(var a, var b)    // <- error: not for method parameters
    //     { return a + b; }
}

// and the inferred type can surprise:
var value = 1;                  // int
// value = 1.5;                 // <- error: the type is fixed once inferred
var list = new java.util.ArrayList<>();   // ArrayList<Object>, not what you meant
System.out.println(value);