What do the SOURCE , CLASS and RUNTIME encapsulate in the java.lang.annotation.RetentionPolicy enumeration java.lang.annotation.RetentionPolicy ?
|
1 answer
Consider the question on the example of the annotation @Override , which indicates a method override.
This is what @Override looks @Override in its implementation.
@Retention(RetentionPolicy.SOURCE) public @interface Override { } SOURCEin this case indicates that the@Overrideannotation (like the other to which this rule will apply) will be "dropped" during compilation.CLASS- as another rule, indicates that the annotation to which it will be applied will be saved in a file with the.classextension at compile time, but will not be available to theJVMvirtual machine at run time.RUNTIME- as another rule, indicates that the annotation to which it will be applied will be saved in a file with the.classextension at compile time, and will be available to theJVMvirtual machine at runtime.
- And what's the point of not discarding, but making it inaccessible to the JVM? That is,
CLASSis meant. - αλεχολυτ
|