views:

19

answers:

1

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 "";
}
A: 

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

lexicore