【发布时间】:2011-03-15 20:08:27
【问题描述】:
刚刚遇到这个问题:
List<DataNode> a1 = new ArrayList<DataNode>();
List<Tree> b1 = a1; // compile error: incompatible type
DataNode 类型是 Tree 的子类型。
public class DataNode implements Tree
令我惊讶的是,这适用于数组:
DataNode[] a2 = new DataNode[0];
Tree[] b2 = a2; // this is okay
这有点奇怪。任何人都可以对此作出解释吗?
【问题讨论】: