Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to suppress lombok warnings

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.

like image 433
Bukharov Sergey Avatar asked Sep 05 '17 14:09

Bukharov Sergey


1 Answers

Use @Builder.Defaultto add default behavior for your Builder

@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.

like image 150
Daniel Taub Avatar answered Sep 19 '22 13:09

Daniel Taub