Lombok @Getter 和 Collections 的副本

Lombok @Getter and copies of Collections

List 字段上使用 @Getter 工作正常,但在尝试升级到 Java 8 时遇到 ConcurrentModificationException,因为 getter 生成Lombok 不执行字段的复制,如果您希望防止实例状态的外部修改,这是必不可少的。

关于如何让 Lombok 在 getter 上复制 Collection 的任何想法,或者我只能自己编写吗?

来自 @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 您必须自己编写。