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.

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...