在 Lombok 中省略一个 Setter/Getter
我想在 Lombok 中使用数据类。由于它有大约十几个字段,我用 @Data
对其进行注释,以生成所有的 setter 和 getter。但是,有一个特殊字段我不希望为其实现访问器。
如何让 Lombok 省略该字段?
I want to use a data class in Lombok. Since it has about a dozen fields, I annotated it with @Data
in order to generate all the setters and getters. However, there is one special field for which I don't want the accessors to be implemented.
How do I make Lombok omit this field?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将访问级别传递给
@Getter
和@Setter
注释。这对于使 getter 或 setter 受到保护或私有非常有用。它还可用于覆盖默认值。使用
@Data
,默认情况下您可以公开访问访问器。现在,您可以使用特殊访问级别NONE
来完全省略访问器,如下所示:You can pass an access level to the
@Getter
and@Setter
annotations. This is useful to make getters or setters protected or private. It can also be used to override the default.With
@Data
, you have public access to the accessors by default. You can now use the special access levelNONE
to completely omit the accessor, like this:根据 @Data 描述 您可以使用:
According to @Data description you can use: