Skip to content

Instantly share code, notes, and snippets.

@juliano
Created December 12, 2011 12:52
Show Gist options
  • Save juliano/1467017 to your computer and use it in GitHub Desktop.
Save juliano/1467017 to your computer and use it in GitHub Desktop.
Builder imutável
public final class PersonImmutableBuilder {
private final String name;
private final String cpf;
public PersonImmutableBuilder() {
this(null, null);
}
private PersonImmutableBuilder(final String name, final String cpf) {
this.name = name;
this.cpf = cpf;
}
public PersonImmutableBuilder withName(final String name) {
return new PersonImmutableBuilder(name, this.cpf);
}
public PersonImmutableBuilder withCpf(final String cpf) {
return new PersonImmutableBuilder(this.name, cpf);
}
public Person build() {
return new Person(name, cpf);
}
public class Person {
private final String name;
private final String cpf;
private Person(final String name, final String cpf) {
this.name = name;
this.cpf = cpf;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment