dimanche 12 mai 2019

Retrieve annotation by name

I know it's possible to get a class by name, using

public String className = "someName";
public Class<?> c = Class.forName(className);

Is it possible to retrieve an annotation by name? I tried this:

public String annotationName = "someName";
public Class<?> c = Class.forName(annotationName);

And then casting c to Class<? extends Annotation>, which works, but I get an Unchecked cast warning.

I also tried

public String annotationName = "someName";
public Class<? extends Annotation> c = Class.forName(annotationName);

But when I do that I get the error Incompatible types. Required: Class Found: Class>





Aucun commentaire:

Enregistrer un commentaire