Skip to content

Instantly share code, notes, and snippets.

@mohiji
Created July 8, 2016 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohiji/3e45766e02008b10f2f33d25e800cd1d to your computer and use it in GitHub Desktop.
Save mohiji/3e45766e02008b10f2f33d25e800cd1d to your computer and use it in GitHub Desktop.
Really basic immutable models for Java/GWT.
import static com.google.common.base.Preconditions.checkNotNull;
public class ImmutableModel {
private final int id;
private final String label;
public ImmutableModel(int id, String label) {
this.id = id;
this.label = checkNotNull(label);
}
public int getId() {
return id;
}
public String getLabel() {
return label;
}
public ImmutableModel withId(int newId) {
return new ImmutableModel(newId, label);
}
public ImmutableModel withLabel(String newLabel) {
return new ImmutableModel(id, newLabel);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment