Following JEP 286: Local-Variable Type Inference description
I am wondering, what the reason is for introducing such a restriction, as:
Main.java:199: error: cannot infer type for local variable k var k = { 1 , 2 }; ^ (array initializer needs an explicit target-type)
So for me logically it should be:
var k = {1, 2}; // Infers int[]
var l = {1, 2L, 3}; // Infers long[]
Because Java compiler can already infer properly the type of an array:
void decide() {
arr(1, 2, 3); // call void arr(int ...arr)
arr(1, 2L, 3); // call void arr(long ...arr)
}
void arr(int ...arr) {
}
void arr(long ...arr) {
}
So what is the impediment?