Annotation(注解)_注解的自定义

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 {
 男,女;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值