给定一个随机的类:
public class A<T> {
public T t;
public A () {} // <-- why is this constructor necessary for B?
public A (T t) {
this.setT(t);
}
public T getT () {
return this.t;
}
protected void setT (T t) {
this.t = t;
return;
}
}
还有一个扩展类:
public class B extends A<Integer> {
public B (Integer i) {
this.setT(i);
}
}
为什么B要求A有空构造函数?我原以为它会想要使用相似的构造函数而不是默认构造函数。我尝试编译没有默认构造函数的代码,但是我却得到了以下错误消息...
java.lang.NoSuchMethodError: A: method <init>()V not found at B.<init>
有人能解释一下这是为什么吗?