I wonder why does this piece of code compile successfully?
Source code:
abstract class A
{
public abstract A s
This is a surprisingly meaningless piece of code.
All it is saying is that the class A
takes a generic type K
that is a Number
and there is a method useMe
that returns an A
with some pointless extra restriction on T
(other than being a Number
obviously).
Here's an implementation to show how little is being said by the sugar:
abstract class A {
public abstract A super M> useMe(A super M> k);
}
class B extends A {
@Override
public A super M> useMe(A super M> k) {
// Not much more you can do here but this.
return k;
}
}
The ? super M
stuff is just meaningless gobbledegook - all the compiler can derive from it is that both the parameter passed to it and the result returned must be a superclass of a specific unnamed class.
Generics are there to make detection of coding mistakes easy at compile time. Using mumbo-jumbo such as this is just misleading obfuscation.