将lambda函数存储在变量中?

Mun*_*sir 0 java lambda java-8

众所周知,在java-8中我们可以将函数/方法存储在变量中.通过使用以下方式.

    @FunctionalInterface
    public interface MyInterface {

      public string getValue(int val1, int val2);

    }


    public class MyClass {

    static String someFun(int val1, int val2) {
       return ""+(val1+val2)

    }

     static BiFunction<Integer, Integer, String> testParamFun = (a,b) -> ""+(a+b);

    public static void main(String[] args){

       MyInterface intr = MyClass::someFun;
       System.out.println(int.getValue(2,4)); // outpur will be "6" 

       /* i want this, but it give me compile time error? 
         I want to store that function in variable like i was doing in above case. */

   MyInterface inter = MyClass::testParamFun;
   System.out.println(inter.getValue(4,5)); // it gives me error.
   // then i tried this
   System.out.println(inter.apply(4,5)); // i got error again. 


    }

    }
Run Code Online (Sandbox Code Playgroud)

我的问题是,我如何存储BiDirection变量类型MyInterface

ass*_*ias 5

你需要参考BiFunction方法:

MyInterface int_ = MyClass.testParamFun::apply;
Run Code Online (Sandbox Code Playgroud)