The below @Override
annotation indicates that I am not overriding the method defined in the interface. How do I use generics with my concrete class so that it overrides the interface method?
public interface AInterface<T extends MyType> {
void do(T thing)
}
public abstract class BaseMyClass implments AInterface {
// other stuff
}
// AType extends MyType
public class MyClass extends BaseMyClass <AType> {
@Overide
public void doThing(AType atype) {
}
}
BaseMyClass
is implementing the rawtype of AInterface
, you either need to extend the generic to the abstract class itself or define it:
public abstract class BaseMyClass implments AInterface<AType>
public abstract class BaseMyClass<E extends MyType> implments AInterface<E>
BaseClass<AType>
(assuming you meant BaseMyClass
) isn't actually giving you a AInterface<AType>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.