Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Builder {
- public static void main(String[] args) {
- new ImmutableA.Builder().i(1).build();
- }
- }
- class ImmutableA {
- private final int i;
- private final String str;
- private ImmutableA(Builder builder) {
- i = builder.i;
- str = builder.str;
- System.out.println(i +" "+ str);
- }
- public static class Builder {
- private int i;
- private String str;
- public Builder i(int i) {
- this.i = i;
- return this;
- }
- public Builder str(String str) {
- this.str = str;
- return this;
- }
- public ImmutableA build() {
- return new ImmutableA(this);
- }
- }
- }
Add Comment
Please, Sign In to add comment