R. Karlus
R. Karlus

Reputation: 2256

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.

Upvotes: 0

Views: 43

Answers (1)

vc73
vc73

Reputation: 417

"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

Upvotes: 1

Related Questions