为什么不打印 666
@Report("pppp") public class Person {
@Report(type = 1, level = "000") public String name;
public int age;
@Report public Person() { }
@Report public void run() { }
public void skip() { }
public void hello(@NotNull @Report2 @Report(type = 5) String name, @NotNull String prefix) { }
}
System.out.println("_________________________________________"); Method hello = Person.class.getMethod("hello", String.class, String.class); Annotation[][] annotation = hello.getParameterAnnotations(); for (Annotation annotation1 : annotation[0]) { if (annotation1 instanceof NotNull) { // @NotNull注解 NotNull n = (NotNull) annotation1; System.out.println(666); } if (annotation1 instanceof Report) { // @Report注解 Report r = (Report) annotation1; System.out.println(r); }
if (annotation1 instanceof Report2) { // @Report注解 Report2 r2 = (Report2) annotation1; System.out.println(r2); } }
打印结果
_________________________________________
@com.itranswarp.learnjava.annotation.Report2(type=0, value=, level=info)
@com.itranswarp.learnjava.annotation.Report(type=5, value=, level=info)
Sign in to make a reply
🌙
为什么不打印 666
@Report("pppp")
public class Person {
@Report(type = 1, level = "000")
public String name;
public int age;
@Report
public Person() {
}
@Report
public void run() {
}
public void skip() {
}
public void hello(@NotNull @Report2 @Report(type = 5) String name, @NotNull String prefix) {
}
}
System.out.println("_________________________________________");
Method hello = Person.class.getMethod("hello", String.class, String.class);
Annotation[][] annotation = hello.getParameterAnnotations();
for (Annotation annotation1 : annotation[0]) {
if (annotation1 instanceof NotNull) { // @NotNull注解
NotNull n = (NotNull) annotation1;
System.out.println(666);
}
if (annotation1 instanceof Report) { // @Report注解
Report r = (Report) annotation1;
System.out.println(r);
}
if (annotation1 instanceof Report2) { // @Report注解
Report2 r2 = (Report2) annotation1;
System.out.println(r2);
}
}
打印结果
_________________________________________
@com.itranswarp.learnjava.annotation.Report2(type=0, value=, level=info)
@com.itranswarp.learnjava.annotation.Report(type=5, value=, level=info)