Initializing Lists
Why is this
List<Integer> a = new List<Integer>({1,2,3})
not possible?
Simple workaround
class ListInit {
public static void main(String args[]){
List<Integer> a = Arrays.asList(1,2,3);
}
}
but,
Is it not possible to initialize a List with an array literal?
It is!
That means Arrays.asList() should work with an array literal.
But the below doesn’t work.
List<Integer> a = Arrays.asList({1,2,3});
Although this does with the ’new’ keyword.
List<Integer> a = Arrays.asList(new Integer[] {1,2,3})