Created
August 8, 2017 09:04
-
-
Save hanbei/91d807c52a5becb02b5548009d49e030 to your computer and use it in GitHub Desktop.
Person StepBuilder in Java 8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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