I have started using the Lombok library, and I am unable to figure out the difference between using a wither & a builder.
@Builder
@Wither
public class Sample {
private int x;
private int y;
}
Now I can create an object in 2 ways:
Sample s = new Sample().builder()
.x(10)
.y(15)
.build();
OR
Sample s = new Sample()
.withx(10)
.withy(10);
What is the difference between the two? Which one should I use?
@Builder
is used to create mutable objects, @Wither
for immutables.
Disclosure: I am a lombok developer.