I'd like to annotate some classes with a @MyEntity annotation
public @interface MyEntity {}
@MyEntity
public class MyClass { ... }
And define a collection where only classes with that annotation are allowed (with no need to define them as public class MyClass implements XXX
):
List<MyEntity> list = new ArrayList<MyEntity>();
list.add(new MyClass())
The above code results in a complation error "The method add(MyEntity) in the type ArrayList is not applicable for the arguments (MyClass)". Is there a way to define a collection that only allows objects with a given annotation?