Created
May 10, 2016 01:41
-
-
Save tonymorris/06a4c3f3a4b846001ff2b119e4482ee5 to your computer and use it in GitHub Desktop.
This file contains 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
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