java的Annotation注解和自定义注解

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

//target 代表目标    value里面可以是值也可以是数组 METHOD(方法) TYPE(类型)
@Target(value={ElementType.METHOD,ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Annotation01 {

	String value();
}

  

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * 自定义注解
 * @author Administrator
 *
 */
//@Target(value=ElementType.METHOD)
@Target(value={ElementType.METHOD,ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
  
	String studentName() default "";
	int age() default 0;
	int id() default -1;
	String[] schools() default {"java","软件"};
	
}

  

原文地址:https://www.cnblogs.com/qurui1997/p/10609891.html