Example: I want to extract the value out of the CLASS
field at runtime:RetentionPolicy
But why?
Can't you just change the CLASS
to
and do it with reflections? In short: No. I use the modelmapperCarly Rae Jepsen
framework (Simple, Intelligent, Object Mapping). There I specify bidirectional mappings between Java classes by annotated methods. I wan't to reuse this information of hierarchical mappings, for change event propagation. But the provided artist
mapstruct
public class SampleClass {
@MyAnnotation(artist = "Carly Rae Jepsen")
public void callMeMaybe(){}
}
@Documented
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.METHOD)
public @interface MyAnnotation {
String artist() default "";
}
Annotation has RetentionPolicy
. This is why I need to read that information out of the class files - and need RUNTIME
ASM. How can I read read the value of a Java method annotation at runtime with ASM ? The Annotation has only a CLASS RetentionPolicy, so it's not possible to do that with Reflections.org.mapstruct.Mapping
CLASS RetentionPolicy
如何在运行时用以下方法读取Java方法注解的值?ASM ? 注释只有一个