任何人都可以解釋我爲什麼在下面的代碼創建只有B時,得到一個錯誤:java中收集
public class factory {
public <T> void createA(List<I<T>> c) {
A a = new A(c);//warning here
}
public <T> void createB(List<I<T>> c) {
B b = new B(c);//error here: The constructor B(List<I<T>>) is undefined
}
}
interface I<T> {
}
class B implements I<Integer> {
public B(List<I<?>> c) {
}
}
class A<T> implements I<T> {
public A(List<I<?>> c) {
}
}
B級是通用的,A是沒有,但我不知道爲什麼它的事項在這種情況下。
我希望你已經導入了'List'。如果不是,我認爲這是錯誤。 –
你得到了什麼錯誤信息? – 2013-06-19 14:19:26
我忽略了導入語句,這裏沒有問題。我得到:「構造函數B(列表>)是未定義的」 「,因爲我在評論中寫道。 –