I wonder why does this piece of code compile successfully?
Source code:
abstract class A
{
public abstract A s
There are two parts to your question:
Part 1: What is the
?
The presence of a generic parameter on a method makes it a "typed method", which means the method has a generic type that is determined by the caller, usually by inference. It may be bounded. If the class has a type too and the method is an instance method, the two types are unrelated.
Part 2:
The generic types must match exactly. The reason boils down to the fact that if B
is a subtype of A
, SomeClass
is not a subtype of SomeClass
, more particularly, SomeClass
is not a subtype of SomeClass super A>
.