I have a problem with my enum. I need to call different functions based on enum values I can do it based on switch case but it is not a solution in my case sinse I have approx 50 values. So what I am trying to do is pass each function in enum constructor with dynamic runtime values.Below is some example code snippet to make it more clear.
public enum TestEnum {
TEST_ENUM1("1", TestUtil.one(name)),
TEST_ENUM2("2", TestUtil.two(name));
private String display;
private Runnable function;
private static String name;
TestEnum(String number,Runnable function){
this.display = number;
this.function = function;
}
public String getDisplay() {
return display;
}
public Runnable getFunction() {
return function;
}
}
and to execute this I need to iterate over thin enum and call each method with dynamic value for name field.
for (TestEnum enumv : TestEnum.values()) {
enumv.getFunstion.execute();
}
Is it possible to achieve the same if yes then please let me know the best way to do it. Thanks