Last active
December 6, 2017 14:27
-
-
Save poetix/6627a3a33216098cefbae2e72af5bf99 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
public final class Person { | |
// Publicly accessible, all parameters validated. | |
public static Person with(String name, int age, String favouriteColour) { | |
checkArgument(age > 0, "age must be greater than 0"); | |
return new Person( | |
checkNotNull(name, "name must not be null"), | |
age, | |
checkNotNull(favouriteColour, "favouriteColour must not be null") | |
); | |
) | |
private final String name; | |
private final int age; | |
private final String favouriteColour; | |
// Private, does nothing but assign parameters to fields | |
private Person(String name, int age, String favouriteColour) { | |
this.name = name; | |
this.age = age; | |
this.favouriteColour = favouriteColour; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment