Cherry
Cherry

Reputation: 33544

How parametrize annotation?

With java I can write something like that

public <T extends Enum> getValue (Class<T> clazz) {}

Is there a way to parametrize not from Enum, but from Annotation? So example I want write something like this:

public <T extends @interface> getValue (Class<T> clazz) {}

My goal is to be insure during compilation time that clazz variable is annotation. Any ideas? (except call class.isAnnotation inside a method)

Upvotes: 1

Views: 162

Answers (1)

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 279960

Yes, all annotation types are subclasses of java.lang.annotation.Annotation.

The common interface extended by all annotation types.

Use

public <T extends Annotation>  void /* or whatever */ getValue (Class<T> clazz) {}

Upvotes: 1

Related Questions