Given a random class:
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;
}
}
And an extended class:
public class B extends A<Integer> {
public B (Integer i) {
this.setT(i);
}
}
Why does B require A to have the empty constructor? I would have assumed it would want to use the similar constructor instead of the default constructor. I tried compiling without the default constructor, but I get the following message without it...
java.lang.NoSuchMethodError: A: method <init>()V not found at B.<init>
Can anyone explain why this is?
See Question&Answers more detail:os