I have the following test code:
public interface Container<I> { public void addClass(Class<?> clazz); } public class MyContainer implements Container { public void addClass(Class<?> clazz) {} }
and I get the following error when trying to compile these two classes:
MyContainer.java:1: MyContainer is not abstract and does not override the abstract addClass method (java.lang.Class) in the container
If I add a type to the Container container in MyContainer (e.g. <Object> ), I will not get an error.
The problem is that I introduced the type parameter in Container, which is part of the public API, so for compatibility I cannot use all implementation classes that cannot be compiled.
Does anyone have any idea? Is this a type erase problem? Is there any workaround?
java override generics type-erasure type-parameter
Dale wijnand
source share