Skip to content

Instantly share code, notes, and snippets.

@benhardy
Created December 3, 2014 16:05
Show Gist options
  • Save benhardy/ce0a20470f815c726252 to your computer and use it in GitHub Desktop.
Save benhardy/ce0a20470f815c726252 to your computer and use it in GitHub Desktop.
typesafe fluent builders are much more convenient now Java has lambdas
// 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