package annotation; /** * 注解就是代码中的特殊标记,用于告诉程序该如何运行 * 在注解中采用属性描述 * @author root */ //定义注解使用@interface关键字 public @interface MyAnnotation { /** * 在注解中使用属性描述,属性的类型只能是以下类型: * *String类型 * *8大基本数据类型 * *Class类型 * *枚举类型 * *注解类型 * *以上类型的一维数组 * @return */ String name(); int age(); Class clazz(); Gender gender(); MyAnnotation2 my2(); String [] arr(); }
package annotation;
//调用注解
public class Servlet {
/*
* 调用的时候如果数组的个数只有一个的时候数组的括号是可以不写的。
*/
@MyAnnotation(age = 38, clazz = String.class, gender = Gender.男, my2 = @MyAnnotation2(name = "lhm"), name = "zxx", arr = { "" })
public void aa(){
}
}
/**
<father>
<name></name>
<age></age>
<child>
<name></name>
</child>
</father>
**/
package annotation; //声明一个注解 public @interface MyAnnotation2 { String name(); }
package annotation; public enum Gender { 男,女; }