package com.liming.study;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(value = {ElementType.METHOD,ElementType.TYPE})
@Retention(value = RetentionPolicy.RUNTIME)
public @interface MyAnnotation { //自定义注解
String value() default "";
int id() default 0;
String[] list() default {"胖虎"};
}
package com.liming.study;
import java.util.ArrayList;
import java.util.List;
public class AnnotationTest {
public static void main(String[] args){
System.err.println("Hello Annotation");
test();
}
@MyAnnotation(value="Hello",id=123,list = {"大雄","小夫"})
private static void test(){
System.err.println("Test");
// List list = new ArrayList();
}
@Override
public String toString() {
return super.toString();
}
}
网友评论