微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – Lombok @Getter和Collections的副本

在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.

原文地址:https://www.jb51.cc/java/129500.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐