One minute
public class Invoice {
private final String number;
private final String date;
private Invoice(Builder builder) {
this.number = builder.number;
this.date = builder.date;
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private String number;
private String date;
private Builder() {}
public Builder number(String number) {
this.number = number;
return this;
}
public Builder date(String date) {
this.date = date;
return this;
}
public Invoice build() {
return new Invoice(this);
}
}
}
Moder implementation:
@Builder
public class Invoice {
private final String number;
private final String date;
}
Some other languages partially solve problems using named parameters. For example, in Kotlin, you can use default values for parameters.
Invoice(
number = "123",
date = "2021-01-01"
)
122 Words
0001-01-01 01:24