What do the SOURCE , CLASS and RUNTIME encapsulate in the java.lang.annotation.RetentionPolicy enumeration java.lang.annotation.RetentionPolicy ?

    1 answer 1

    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 { } 
    • SOURCE in this case indicates that the @Override annotation (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 .class extension at compile time, but will not be available to the JVM virtual 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 .class extension at compile time, and will be available to the JVM virtual machine at runtime.
    • And what's the point of not discarding, but making it inaccessible to the JVM? That is, CLASS is meant. - αλεχολυτ
    • @alexolut: An interesting question. This is what I managed to find out about CLASS . - TimurVI