Search code examples
javareflectionannotations

Can I use a class type parameter inside an annotation?


Think about the given scenario:

public @interface SomeThirdAnnotation {
    Class<? extends Something> value();
}

@SomeThirdAnnotation(T)
public abstract class MyClass<T extends Something> {
    // my code
}

Can this be possible in JAVA?

Is there any way to use a class type parameter inside annotations, because doing it will drastically remove code from the abstract class children.

Thank you very much for those who try to help me.


Solution

  • "Annotations cannot be generic or specify a throws clause. Annotations must return: an enum, primitive type or an annotation, String, or Class object. They can also return an array of these types." source: here