Java equivalent of function mapping in Python

前端 未结 7 1449

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

    Unfortunately, Java does not have first-class functions, but consider the following interface:

    public interface F {
      public B f(A a);
    }
    

    This models the type for functions from type A to type B, as first-class values that you can pass around. What you want is a Map>.

    Functional Java is a fairly complete library centered around first-class functions.

提交回复
热议问题