1 | sclass Alt<A, B> {
|
2 | byte which; |
3 | O value; |
4 | |
5 | *() {}
|
6 | *(int which, O *value) { this.which = (byte) which; }
|
7 | |
8 | bool isA() { ret which == 1; }
|
9 | bool isB() { ret which == 2; }
|
10 | |
11 | A a() { if (which != 1) _failMe(); ret (A) value; }
|
12 | B b() { if (which != 2) _failMe(); ret (B) value; }
|
13 | |
14 | void _failMe {
|
15 | fail("Alt object is of wrong type: " + shortClassName(value));
|
16 | } |
17 | } |
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1009167 |
| Snippet name: | Alt - union type [now called Either] |
| Eternal ID of this version: | #1009167/4 |
| Text MD5: | e1c5d3e033c4dd1c1afd719d74baa533 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2017-07-12 13:28:58 |
| Source code size: | 400 bytes / 17 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 717 / 1319 |
| Version history: | 3 change(s) |
| Referenced in: | [show references] |