Initialize ArrayList<Long>
问题 Why I can initialize ArrayList, like this: ArrayList<Integer> x = new ArrayList<Integer>(Arrays.asList(1,2)); But got Error when using: ArrayList<Long> x = new ArrayList<Long>(Arrays.asList(1,2)); 回答1: Explanation Java automatically transforms int to long if needed. However, Java does not do the same if a transformation from Integer to Long is needed. The function Arrays.asList(...) returns a List<E> with E being the type used as parameters. As you use 1, 2, 3 the type is int . However the