sclass Either { byte which; O value; *() {} *(int which, O *value) { this.which = (byte) which; } bool isA() { ret which == 1; } bool isB() { ret which == 2; } A a() { if (which != 1) _failMe(); ret (A) value; } B b() { if (which != 2) _failMe(); ret (B) value; } A aOpt() { ret which != 1 ? null : (A) value; } B bOpt() { ret which != 2 ? null : (B) value; } void _failMe { fail("Either object is of wrong type: " + shortClassName(value)); } toString { ret "Either" + (isA() ? "A" : "B") + "(" + value + ")"; } }