Does not exist due to security reasons
UnionType unionType = new TypeA(); Integer count = unionType.when(new UnionType.Cases() { @Override public Integer is(TypeA typeA) { // TypeA-specific handling code } @Override public Integer is(TypeB typeB) { // TypeB-specific handling code } });