java注解____注解的入门demo

package com.annotation.test;

import static java.lang.annotation.ElementType.CONSTRUCTOR;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.LOCAL_VARIABLE;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;

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


/**
 * @author Administrator
 * 自定义用户注解
 */
//注解定义
@Documented  
//注解生命周期
@Retention(RetentionPolicy.RUNTIME) 
//注解的作用范围 设定作用构造器 字段 方法 包等
@Target(value={CONSTRUCTOR, FIELD, LOCAL_VARIABLE, METHOD, PACKAGE, PARAMETER, TYPE})
public @interface UserAnnotation {
	//定义注解 的基本的
	String name();
	//定义属性值
	String password();
	
}

//

package com.annotation.test;
@UserAnnotation(name="zhangsan", password = "123456")
public class TestMyAnnotation {
	
	public static void main(String[] args) {
		//使用反射进行参数注解
		UserAnnotation annotation=TestMyAnnotation.class.getAnnotation(UserAnnotation.class);
		//测试注解
		System.out.println(annotation.name()+"__"+annotation.password());
	}
}

//运行结果

zhangsan__123456

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值