0

What is the purpose of these java.lang.annotation imports in this code? Why are they needed to define MyAnnotation?

import java.lang.annotation.Documented;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface MyAnnotation {
  String value() default "";
}
cafe
  • 263
  • 2
  • 8

1 Answers1

1

@Documented and @Inherited are not required. @Retention(RetentionPolicy.RUNTIME) is only needed if you want to process the annotations in the runtime.

lexicore
  • 42,748
  • 17
  • 132
  • 221