参考文章:
(1)https://www.cnblogs.com/extjs4/p/6411507.html 关于注解第一篇
(2)https://www.cnblogs.com/extjs4/p/6817064.html 关于注解第二篇
所有的表示注解的类如下:
举个例子,如下:
package com.test11;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface MzTargetPackage {
// 基本类型的包装类
boolean isCanNull() default true;
int num() default 100;
// String类型
public String version() default "";
// enum类型
public enum Color{ BULE,RED,GREEN};
Color fruitColor() default Color.GREEN;
// 数组类型 {"a","b","c"}
String[] value();
Code compoundTest();
Class<String> getC();
}
使用如上的注解,如下:
package com.test11;
public class Test {
@MzTargetPackage(isCanNull =true,
num=100,
version = "1.1.0",
fruitColor=MzTargetPackage.Color.BULE,
value={"a,","b","c"},
compoundTest=@Code(author = "closedevice",date="20161225"),
getC = String.class
)
@CSAnn
private void process() { }
}
(1)ArrayAttributeProxy属性代理了value={"a,","b","c"}
(2)CompoundAnnotationProxy属性代理了compoundTest=@Code(author = "closedevice",date="20161225")
而整个@MzTargetPackage注解也用一个CompoundAnnotationProxy来表示,如下:
(3)EnumAttributeProxy属性代理了fruitColor=MzTargetPackage.Color.BULE
(4)AttrConstant属性存储了剩下的属性值
为什么要使用如上三个属性代理?