Java pass method reference as parameter to other method

前端 未结 5 1427
暗喜
暗喜 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:17

    MethodReference is a class for reflection purpose. Your code actually need a lambda-like object, which shall be a single method interface in Java 8.

    Without Java 8 or reflection there is no way to directally meet your need though. But you can always pass some internal representation of the method to another calss, and to do so you have to write code to process this internal representation.

提交回复
热议问题