Skip to content

Instantly share code, notes, and snippets.

@tonymorris
Created May 10, 2016 01:41
Show Gist options
  • Save tonymorris/06a4c3f3a4b846001ff2b119e4482ee5 to your computer and use it in GitHub Desktop.
Save tonymorris/06a4c3f3a4b846001ff2b119e4482ee5 to your computer and use it in GitHub Desktop.
abstract class IntOrString {
private IntOrString() {}
public static class IsInt extends IntOrString {
private final int i;
public IsInt(int i) {
this.i = i;
}
int get() {
return i;
}
}
public static class IsString extends IntOrString {
private final String s;
public IsString(String s) {
this.s = s;
}
String get() {
return s;
}
}
// todo, library support, knowing that this invariant holds:
// given IntOrString x, then (x instanceof IsInt) || (x instanceof IsString)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment