Lombok @Getter and copies of collections

Using @Getter in the List field works fine, but when trying to switch to Java 8, I came across a ConcurrentModificationException because the recipient created by Lombok does not execute a copy of the field, which is important if you want to prevent external modification of the state of the instance.

Any ideas on how I can get Lombok to copy Collection to getters, or am I just writing my own?

+5
source share
1 answer

From @ Getter and @Setter Documentation :

You can annotate any field with @Getter and / or @Setter so that lombok automatically generates default getter / setter. By default, getter simply returns a field and is called getFoo if the field is called foo (or isFoo if the field type is boolean). The default installer is called 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.

Since you want more functionality and then the default recipient, you will have to write your own.

+3
source

Source: https://habr.com/ru/post/1239778/


All Articles