gpt4 book ai didi

java - 在类上注释时,如何配置 lombok 以生成静态成员的 Getter/Setter

转载 作者:行者123 更新时间:2023-12-04 12:16:43 58 4
gpt4 key购买 nike

我有一个所有静态成员的类。静态成员的数量超过 10 个(可能会随着时间的推移而增加)。

我正在使用 lombok,我想使用单个 @Getter 为所有静态成员生成 Getter/Setter和 @Setter类上的注释就像我们对非静态成员所做的一样。

我知道

You can also put a @Getter and/or @Setter annotation on a class. In that case, it's as if you annotate all the non-static fields in that class with the annotation.



我也知道

We can annotate static fields individually using @Getter @Setter to generate Getters/Setters for static fields.



但这看起来很难看,我想让我的类(class)看起来尽可能干净。

有什么方法可以配置/覆盖@Getter 和@Setter 注释,以便我可以对类进行注释,并为包括静态和非静态成员在内的所有成员生成 Getter 和 Setter,毕竟这些方法所做的是返回提到的多变的。

更准确地说,我希望以下代码片段为所有类变量生成 Getter 和 Setter-
@Getter
@Setter
public class myClass {
private static String d;
private static SomePojo c;

private String a;
private Integer b;
private SomeClass d;

}

最佳答案

添加 @Getter到静态成员本身,它应该可以工作。

@Getter
private static final String DEFAULT_VAL = "TEST";

关于java - 在类上注释时,如何配置 lombok 以生成静态成员的 Getter/Setter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61020852/

58 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com