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