Java equivalent of function mapping in Python

前端 未结 7 1428

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:54

    As everyone else said, Java doesn't support functions as first-level objects. To achieve this, you use a Functor, which is a class that wraps a function. Steve Yegge has a nice rant about that.

    To help you with this limitation, people write functor libraries: jga, Commons Functor

    0 讨论(0)
提交回复
热议问题