Consider the following example:
This fails with two compiler errors:
If I change
Class<? extends Base<?>> into
Class<? extends Base> then it works, except Eclipse shows a warning:
Base is a raw type. References to generic type Base<T> should be parameterized
Since I want something like this in one of my APIs I want to handle this as cleanly as possible. Right now I have my method return
Set<Class<? extends Base<?>>> which causes class literals for all generic sub types to require an explicit cast (which I have to suppress with
@SuppressWarnings("unchecked")). The alternative is make the method return
Set<Class<? extends Base>> but then my API includes use of a raw type (which I have to suppress with
@SuppressWarnings("rawtypes") in both the interface and implementations). Either way I have to suppress warnings.
Does anyone have suggestions on how to fix this in the cleanest way? Or have I already chosen the cleanest way?