Skip to content

Instantly share code, notes, and snippets.

@hanbei
Created August 8, 2017 09:04
Show Gist options
  • Save hanbei/91d807c52a5becb02b5548009d49e030 to your computer and use it in GitHub Desktop.
Save hanbei/91d807c52a5becb02b5548009d49e030 to your computer and use it in GitHub Desktop.
Person StepBuilder in Java 8
public static class Person {
String name;
int age;
private Person(String name, int age) {
this.name = name;
this.age = age;
}
static PersonWaitingForName create() {
return personName -> age -> new Person(personName, age);
}
interface PersonWaitingForName {
PersonWaitingForAge name(String name);
}
interface PersonWaitingForAge {
Person age(int age);
}
public static void main(String[] args) {
Person charlotte = Person.create()
.name("Charlotte")
.age(25);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment