I have an Entity
@Builder
class MyEntity {
private Set<OtherEntitiy> children = new HashSet<>()
}
And i get a lombok warning.
warning: @Builder will ignore the initializing expression entirely. If you want the initializing expression to serve as default, add @Builder.Default. If it is not supposed to be settable during building, make the field final. Set = new HashSet<>();
The question is: how can i suppress lombok's warning?
Also. I need to initialize children because i want to avoid NullPointerException. Also i can't mark this filed as final because it is not final really. I cant mark filed @Builder.Default
because i wanna create this entity not only with builder and i wanna to save default value for other constructors.
Use
@Builder.Default
to add default behavior for yourBuilder
@Builder
class MyEntity {
@Builder.Default
private Set<String> children = new HashSet<>();
}
You use it on the field that has a default value defined an Lombok
will then pick up the value during object creation
@Builder.Default
functionality was added in lombok v1.16.16.
So if you're using lower version of Lombok
you will not be able to use it.