加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – Lombok @Getter和Collections的副本

发布时间:2020-12-15 00:41:53 所属栏目:Java 来源:网络整理
导读:在List字段上使用@Getter工作正常,但在尝试升级到 Java 8时遇到ConcurrentModificationExceptions,因为Lombok生成的getter不执行字段的副本,如果您希望阻止外部修改实例的状态,这是必不可少的. 任何想法我如何让龙目岛复制集合上的getter,或者我只限于编写我
在List字段上使用@Getter工作正常,但在尝试升级到 Java 8时遇到ConcurrentModificationExceptions,因为Lombok生成的getter不执行字段的副本,如果您希望阻止外部修改实例的状态,这是必不可少的.

任何想法我如何让龙目岛复制集合上的getter,或者我只限于编写我自己的?

解决方法

从 @Getter and @Setter文档:

You can annotate any field with @Getter and/or @Setter,to let lombok generate the default getter/setter automatically.
A default getter simply returns the field,and is named getFoo if the field is called foo (or isFoo if the field’s type is boolean). A default setter is named setFoo if the field is called foo,returns void,and takes 1 parameter of the same type as the field. It simply sets the field to this value.

既然您需要更多功能,那么您必须自己编写默认的getter.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读