Skip to content
Advertisement

Does Lombok toBuilder() method creates deep copy of fields

I am using toBuilder() on an object instance to create a builder instance and then build method to create new instance. The original object has a list, does the new object has reference to same list or a copy of it?

JavaScript
JavaScript

Will lib2 books refer to same list as lib1 books ?

Advertisement

Answer

Yes, the @Builder(toBuilder=true) annotation doesn’t perform a deep copy of the object and only copies the reference of the field.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement