Java equivalent of function mapping in Python

前端 未结 7 1426

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         


        
7条回答
  •  臣服心动
    2021-02-04 15:28

    You could use a Map or Map etc,and then use map.get("function1").invoke(...). But usually these kinds of problems are tackled more cleanly by using polymorphism instead of a lookup.

提交回复
热议问题