Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lombok @Getter and copies of Collections

Using @Getter on a List field works fine, but on attempting to upgrade to Java 8 I encounter ConcurrentModificationExceptions because the getter generated by Lombok does not perform a copy of the field, which is essential should you wish to prevent external modification of the instance's state.

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

like image 526
Alex Avatar asked Jan 04 '16 11:01

Alex


1 Answers

From @Getter and @Setter documentation:

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.

Since you want more functionality then the default getter you'll have to write your own.

like image 89
M.P. Korstanje Avatar answered Nov 01 '22 13:11

M.P. Korstanje