Here, I have an abstract class:
abstract class A<E extends A> {
abstract void foo(E x);
}
Here's a class that extends A
:
class B extends A<B>{
void foo(B x){}
}
And here's another (E
is B
here on purpose):
class C extends A<B>{
void foo(B x){}
}
Both of those classes are valid, and the reasoning for that makes sense to me.
However what confuses me is how this could possibly be valid:
class D extends A{
void foo(A x){}
}
Since when are generics optional like that? I thought the extending class (subclass) of A
would be required to specify an E
?
Edit:
The two answers received so far say that E defaults to an Object if no argument is provided.
Alright - well then why doesn't this work (below)?
class D extends A<Object>{
void foo(Object x){}
}