Java pass method reference as parameter to other method

前端 未结 5 1424
暗喜
暗喜 2021-02-04 07:53

I am trying to pass a selected \"get\"-method of class A to a method in class B. I have checked out Java Pass Method as Parameter, but I was not able to adopt the interface appr

5条回答
  •  被撕碎了的回忆
    2021-02-04 08:33

    There is a workaround: Scala java apis.

    I use Apache Spark and scala offers a series of Anonymous Functions (Function, Function2) which are available since Java 1.5, if I'm not mistaken (although I use it with Java 1.7).
    Here is an answer talking about this. Because otherwise the "Function" class is available only from Java 1.8

提交回复
热议问题