Let's say I have a super-class that defines the following abstract method
public abstract <T extends Interface> Class<T> getMainClass();
Now if I want to override it in some sub-class
public Class<Implementation> getMainClass(){
return Implementation.class;
}
I get a warning about type safety and unchecked conversion:
Type safety: The return type Class<Implementation>
for getMainClass()
from the type SubFoo
needs unchecked conversion to conform to Class<Interface>
from the type SuperFoo
Doesn't Class<Implementation>
fall under Class<T>
if <T extends Interface>
? Is there any way to properly get rid of the warning?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…