lombok @NonNull on字段无法使用getAnnotations读取

问题描述 投票:0回答:1

示例:

@Value
@Builder(toBuilder = true)
@AllArgsConstructor(access = AccessLevel.PUBLIC)
public class A {
    //
    // RecordRootable fields
    //
    @NonNull
    private UUID a;
}

如果IntelliJ反编译器没有说谎,则在类文件中@NonNull批注似乎存在。

现在,我们想使用Field.getAnnotations或类似的东西在运行时从Field读取注释,但未找到任何内容。

我可以使用任何特殊方法来读取此注释吗?

我需要添加其他注释以阅读它吗?

reflection annotations lombok
1个回答
0
投票

似乎注解有@Retention(RetentionPolicy.CLASS)代替@Retention(RetentionPolicy.RUNTIME)因此无法反省地阅读它们

© www.soinside.com 2019 - 2024. All rights reserved.