In python, if I have a few functions that I would like to call based on an input, i can do this:
lookup = {\'function1\':function1, \'function2\':function2, \'fu
As mentioned in other questions, a Map
with anonymous inner classes is one verbose way to do it.
A variation is to use enums in place of the anonymous inner classes. Each constant of the enum can implement/override methods of the enum or implemented interface, much the same as the anonymous inner class technique but with a little less mess. I believe Effective Java 2nd Ed deals with how to initialise a map of enums. To map from the enum name merely requires calling MyEnumType.valueOf(name)
.