Effective Java 第25条:列表优先于数组
数组与泛型的不同点
- 数组是协变的(covariant),泛型是不可变的(invariant)
- 数组是具体化的(reified)
// Fails at runtime!
Object[] objectArray = new Long[1];
objectArray[0] = "I don't fit in"; // Throws ArrayStoreException
// Won't compile!
List<Object> ol = new ArrayList<Long>(); // Incompatible types
ol.add("I don't fit in");
创建泛型数组是非法的
new List<E>[]
new List<String>[]
new E[]