Policy

问题描述 投票:0回答:1
: Annotations are to be recorded in the class file by the compiler but need not be retained by the VM at run time

Example: I want to extract the value out of the CLASS field at runtime:RetentionPolicyBut 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 artistmapstruct

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 RUNTIMEASM. 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 ? 注释只有一个

java assembly reflection annotations modelmapper
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.