我正在理解Java中泛型的概念。我無法理解以下幾行代碼。瞭解Java中列表的列表
import java.util.List;
import java.util.ArrayList;
public final class Main {
public static final void main(final String[] args) {
final List<A> listA = new ArrayList<Main.A>();
//listA.add(new Main.B()); // i understood why this line is an error.
final List<List<A>> listListA = new ArrayList<List<A>>();
listListA.add(new ArrayList<Main.A>());
// Why the above line doesn't throws an error ?
}
private class A {
}
private final class B extends A {
}
}
您是指編譯器錯誤或運行時錯誤? – OldProgrammer 2013-05-12 01:52:11
編譯時錯誤 – 2013-05-12 01:54:04
代碼編譯。沒有錯誤。 http://ideone.com/YetaPJ – 2013-05-12 01:55:28