@MyAnnotation(name="haha")
public class AnnotationTest {
@SuppressWarnings("deprecation")
public static void main(String[] args) {
// TODO Auto-generated method stub
if(AnnotationTest.class.isAnnotationPresent(MyAnnotation.class)){
MyAnnotation anno = (MyAnnotation)AnnotationTest.class.getAnnotation(MyAnnotation.class);
System.out.println(anno.name());
System.out.println(anno.lamp().name());
}
}
}
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
//为注解添加属性
String name();
Lamp lamp() default Lamp.Red;
}
enum Lamp{
Red,Green,Yellow
} |
|