I am trying to figure out how to reference a parameterized interface as an annotation attribute:
public class Example {
public interface MyService<T extends Number> {
T someNumber();
}
public class BaseServiceImpl<T extends Number> implements MyService<T> {
@Override
public T someNumber() {
return null;
}
}
public @interface ServiceType {
Class<? extends MyService<?>> value();
}
@ServiceType(BaseServiceImpl.class)
public static void main(String[] args) {
System.out.println("Hello World");
}
}
The above code fails with a type mismatch on the @ServiceType
annotation. I believe the problem is with the bounds I have specified for the value
attribute. I also noticed that when a type is not generic it works fine; e.g. @ServiceType(IntegerService.class)
works given:
public class IntegerService extends BaseServiceImpl<Integer> { /* ... */ }
What am I missing to get the rid of the mismatch error when trying to supply the generic type?