question about enthuware.ocpjp.i.v11.2.3201
Posted: Sat Jun 06, 2020 4:58 pm
Why is
When I try to declare an empty var,
compiler refuses to run and gives error,
not a valid statement?A var declaration must have an initializer. Without the initializer, the compiler will not be able to deduce the type of the variable.
When I try to declare an empty var,
Code: Select all
public class CompileTimeConstant{
public static void main(String[] args){
var v1;
}
}
Code: Select all
CompileTimeConstant.java:3: error: cannot infer type for local variable v1
var v1;
^
(cannot use 'var' on variable without initializer)
1 error
error: compilation failed