Annotations

From Null-pointer

Jump to: navigation, search

Simple example

package null-pointer;
 
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
 
@Documented
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Cache {
  String cacheName();
  int timeToLiveSeconds() default -1;
}

@Target

This states where the annotation is valid:

  • ElementType.TYPE = class level
  • ElementType.METHOD = method level
  • ElementType.PARAMETER = parameter level

See also

Personal tools