标签:
package com.koyw23.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Ann {
int text();
String textStr();
}
package com.koyw23.Annotation;
@Ann(text = 2, textStr = "name")
public class AnnClass {
private int id;
private int Ann_Name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getAnn_Name() {
return Ann_Name;
}
public void setAnn_Name(int ann_Name) {
Ann_Name = ann_Name;
}
public static void main(String[] args) {
try {
Class<?> clazz = Class.forName("com.koyw23.Annotation.AnnClass");
Ann ann = (Ann) clazz.getAnnotation(Ann.class);
boolean b = clazz.isAnnotationPresent(Ann.class);
if (b) {
System.out.println(ann.text());
System.out.println(ann.textStr());
if(ann.textStr().equals("name")){
System.err.println("nishabi");
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
标签:
原文地址:http://www.cnblogs.com/koyw23/p/5669261.html