Java: Why is this Subclass valid?
- by incrediman
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?