Vector x = new Vector(); // OK ArrayList y = new ArrayList(); // OK List zzz = new ArrayList(); // OK solves problem below but question remains List z = new List(); // WHY? Compiler error: Cannot instantiate
List是一个接口,有点像C ++中有一些= 0方法的类。 你无法实例化它。
但ArrayList “inheritance” List (或者用Java术语,实现它),因此这些引用是赋值兼容的。