使用 Class.isAnnotationPresent() 测试保留策略设置为 SOURCE 或 CLASS (默认值) 的注解是否始终得到负值结果。 这个错误很容易被忽视。
Class.isAnnotationPresent()
SOURCE
CLASS
示例:
{ getClass().isAnnotationPresent(SourceAnnotation.class); //始终为 false } @Retention(RetentionPolicy.SOURCE) @interface SourceAnnotation {}