Guest User

Untitled

a guest
Apr 26th, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. public final class Person {
  2.  
  3. private final String firstName;
  4. private final String lastName;
  5.  
  6. private Person(String firstName, String lastName) {
  7. this.firstName = firstName;
  8. this.lastName = lastName;
  9. }
  10.  
  11. public String getFirstName() {
  12. return firstName;
  13. }
  14.  
  15. public String getLastName() {
  16. return lastName;
  17. }
  18.  
  19. public static Builder builder() {
  20. return new Builder();
  21. }
  22.  
  23. public static final class Builder {
  24. private String firstName;
  25. private String lastName;
  26.  
  27. private Builder() {
  28. }
  29.  
  30. public Builder firstName(String firstName) {
  31. this.firstName = firstName;
  32. return this;
  33. }
  34.  
  35. public Builder lastName(String lastName) {
  36. this.lastName = lastName;
  37. return this;
  38. }
  39.  
  40. public Person build() {
  41. return new Person(firstName, lastName);
  42. }
  43. }
  44. }
Add Comment
Please, Sign In to add comment