Created
December 3, 2014 16:05
-
-
Save benhardy/ce0a20470f815c726252 to your computer and use it in GitHub Desktop.
typesafe fluent builders are much more convenient now Java has lambdas
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
// I probably should make a Maven plugin that generates this code. | |
public final class AddressBuilder { | |
public interface Street2 { | |
City street2(String street2); | |
} | |
public interface City { | |
State city(String city); | |
} | |
public interface State { | |
PostalCode state(String state); | |
} | |
public interface PostalCode { | |
Country postalCode(String postalCode); | |
} | |
public interface Country { | |
Address country(String country); | |
} | |
public Street2 street1(String street1) { | |
return street2 -> city -> state -> postalCode -> country -> | |
new Address(street1, street2, city, state, postalCode, country); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment