Consider I have multiple Enums, each with different values, but all regarding to similar things:
@Getter
@RequiredArgsConstructor
public enum Dict implements Dictionary {
VALUE1 ("Value1"),
VALUE2 ("Value2");
private final String name;
}
@Getter
@RequiredArgsConstructor
public enum Dict2 implements Dictionary {
VALUE3 ("Value3"),
VALUE4 ("Value4");
private final String name;
}
...
Dict3 implements Dictionary{}
Dict4 implements Dictionary{}
Dict5 implements Dictionary{}
etc.
Now I have a method:
public SomeObject getObject(Enum objectType, String someString){
if(ObjectType.Factory == objectType){
return new SomeObject(Dict.valueOf(someString));
} else if(ObjectType.Center == objectType){
return new SomeObject(Dict2.valueOf(someString));
}
(more else ifs)...
return new SomeObject(DictN.valueOf(someString));
}
Is there a nice way to get the specific Dictionary type by Enum provided in a method? Hope I've made myself clear.