Search code examples
javaandroidgenericsannotationsandroid-room

java generic how to ensure type has specified annotation?


I'm trying to create a generic class in android using Java but I want to make sure that the type would take specific classes with specific annotations like this: I have class Table with annotation @Entity

@Entity
public class Table{}

and the generic class should only accept objects that have the @Entity annotation


Solution

  • Simple answer: not possible.

    Annotations represent meta information that isn't available when constructing classes using generic type parameters.