Created
January 14, 2016 15:11
-
-
Save jonaslindmark/a70a49b1b4c5026dde3d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import static com.google.common.base.Preconditions.checkArgument; | |
public class MyObject { | |
public final String name; | |
public final String wat; | |
private MyObject(String name, String wat) { | |
this.name = name; | |
this.wat = wat; | |
} | |
public static BuildName newBuilder() { | |
return new Builder(); | |
} | |
public interface BuildObj { | |
MyObject build(); | |
} | |
public interface BuildName { | |
BuildWat setName(String name); | |
} | |
public interface BuildWat { | |
BuildObj setWat(String name); | |
} | |
public static class Builder implements BuildWat, BuildName, BuildObj { | |
private String name; | |
private String wat; | |
private Builder() {} | |
public BuildWat setName(String name) { | |
checkArgument(name != null); | |
this.name = name; | |
return this; | |
} | |
public BuildObj setWat(String wat) { | |
checkArgument(wat != null); | |
this.wat = wat; | |
return this; | |
} | |
public MyObject build() { | |
return new MyObject(name, wat); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment