sclass Alt<A, B> { 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; } void _failMe { fail("Alt object is of wrong type: " + shortClassName(value)); } }
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: | 476 / 1072 |
Version history: | 3 change(s) |
Referenced in: | #1009173 - Either - union type #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674) |