Suppose I'm trying to write a function to return an instance of the current type. Is there a way to make T
refer to the exact subtype (so T
should refer to B
in class B
)?
class A {
<T extends A> foo();
}
class B extends A {
@Override
T foo();
}
You should be able to do this using the recursive generic definition style that Java uses for enums: