The switch you specified is clearly not working.
I have a (rather strange) substitution: create a "helper enumeration" that contains all the listed values ββand has Map<Request<Enum<?>, HelperEnum> , for example:
private enum HelperEnum { ONE(Enum1.ONE), TWO(Enum1.TWO), THREE(Enum1.THREE), FOUR(Enum2.FOUR), FIVE(Enum2.FIVE); private Enum<?> source; private HelperEnum(Enum<?> source) { this.source = source; } private static Map<Enum<?>, HelperEnum> map; public static HelperEnum lookUp(Enum<?> source) { if (map == null) { map = Arrays.stream(HelperEnum.values()) .collect(Collectors.toMap(x -> x.source, x -> x)); } return map.get(source); }
(unverified!)
So you can do
switch(HelperEnum.lookUp(a_request)){ case ONE: .... case TWO: .... case THREE: .... case FOUR: .... case FIVE: .... }
(a similar version was first published here )
It would be useful to have a common interface implemented by the enumerations listed, but this one will probably work too.
source share