Re:Lombok makes Java cool again
by bobthepanda on Thursday January 31, 2019 @09:29PM
(#19051083)
Can't you just use @Data and @Setter(AccessLevel.NONE)? That's effectively the same as using final but without the keyword.
A builder is just a fancy alternative to a constructor. It is possible to set the value of a final field in a constructor, and it is also possible to have another constructor in the same object that sets a default value for that field. I expect the same flexibility from a builder.
For example:
Now you can get immutable Person objects: But if you do this with Lombok: You cannot do this: The name is stuck at the Builder.Default value. In that sense it is not a default, rather it is the only possible value. A default is supposed to be something that can be overridden.I could use @Data instead of @Value but then the resulting Person objects would be mutable which I don't want.