We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@interface Hints { Hint[] value(); }
@repeatable(Hints.class) @interface Hint { String value(); } @hint("hint1") @hint("hint2") class Person { }
Hint hint = Person.class.getAnnotation(Hint.class); System.out.println(hint); // null
Hints hints1 = Person.class.getAnnotation(Hints.class); System.out.println(hints1.value().length); // 2 这块有错误,使用java8运行空指针异常
Hint[] hints2 = Person.class.getAnnotationsByType(Hint.class); System.out.println(hints2.length); // 2
需要将代码的annotation的加上@retention(RetentionPolicy.RUNTIME),否则默认是@retention(RetentionPolicy.CLASS),不过源代码是有这个策略的,但是文档没有所以为了避免误导开发者,尽量加上这块
原文也有一个issue https://github.com/winterbe/java8-tutorial/issues/36
The text was updated successfully, but these errors were encountered:
No branches or pull requests
需要将代码的annotation的加上@retention(RetentionPolicy.RUNTIME),否则默认是@retention(RetentionPolicy.CLASS),不过源代码是有这个策略的,但是文档没有所以为了避免误导开发者,尽量加上这块
原文也有一个issue
https://github.com/winterbe/java8-tutorial/issues/36
The text was updated successfully, but these errors were encountered: