Guest User

Untitled

a guest
Jan 18th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. public class Builder {
  2. public static void main(String[] args) {
  3. new ImmutableA.Builder().i(1).build();
  4. }
  5. }
  6.  
  7. class ImmutableA {
  8. private final int i;
  9. private final String str;
  10.  
  11. private ImmutableA(Builder builder) {
  12. i = builder.i;
  13. str = builder.str;
  14. System.out.println(i +" "+ str);
  15. }
  16.  
  17. public static class Builder {
  18. private int i;
  19. private String str;
  20.  
  21. public Builder i(int i) {
  22. this.i = i;
  23. return this;
  24. }
  25.  
  26. public Builder str(String str) {
  27. this.str = str;
  28. return this;
  29. }
  30.  
  31. public ImmutableA build() {
  32. return new ImmutableA(this);
  33. }
  34. }
  35.  
  36. }
Add Comment
Please, Sign In to add comment