在龙目岛省略一个Setter / Getter [英] Omitting one Setter/Getter in Lombok

查看:286
本文介绍了在龙目岛省略一个Setter / Getter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Lombok中使用数据类。由于它有大约十几个字段,我用 @Data 注释它以生成所有的setter和getter。但是有一个特殊字段,我不希望实现访问器。

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 getter. However there is one special field for which I don't want to the accessors to be implemented.

Lombok如何省略这个字段?

How does Lombok omit this field?

推荐答案

您可以将访问级别传递给 @Getter @Setter 注释。这对于使getter或setter受到保护或私有非常有用。它也可用于覆盖默认值。

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.

使用 @Data ,您可以通过以下方式公开访问访问者:默认。您现在可以使用特殊访问级别 NONE 来完全省略访问者,如下所示:

With @Data, you have public access to the accessors by default. You can now use the special access level NONE to completely omit the accessor, like this:

@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
private int mySecret;

这篇关于在龙目岛省略一个Setter / Getter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆