Java equivalent of function mapping in Python

前端 未结 7 1430

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

提交回复
热议问题