can';t在java的lambda表达式中将ToIntBiFunction作为参数传递

can';t在java的lambda表达式中将ToIntBiFunction作为参数传递,java,lambda,Java,Lambda,我现在开始学习Java中的Lambda表达式,我试图弄明白为什么这段代码不起作用 我有一门普通课: import java.util.function.ToIntBiFunction; public class testclass { public testclass() { } public static ToIntBiFunction<Integer,Integer> multit2 = (Integer a,Integer b)->{

我现在开始学习Java中的Lambda表达式,我试图弄明白为什么这段代码不起作用 我有一门普通课:

import java.util.function.ToIntBiFunction;


public class testclass {

    public testclass() {

    }
    public static ToIntBiFunction<Integer,Integer> multit2 = (Integer a,Integer b)->{
        return a*b;

    };

    public static Integer multit(Integer a, Integer b) {
        return a*b;
    }
}
testclass类型没有定义适用于此处的multit(对象,对象)

也试图使函数在主,但它给了我同样的错误 代码在我编写时起作用

testclass.multit
而不是

testclass::multit
有人能给我解释一下为什么第二个不起作用,以及如何解决这个问题吗?
谢谢

testclass::multi
表示属于
testclass
的方法
multi
。您拥有的是一个包含函数的字段
testclass.multi
。保存函数的字段与方法不同

class MyClass {
    // This is a method, `MyClass::foo`
    public static Integer foo(Integer a, Integer b) {
        return a*b;
    }
    // This is a field holding a function, `MyClass.bar`
    public static ToIntBiFunction<Integer, Integer> bar = (Integer a,Integer b)-> {
        return a*b;
    };
}
class-MyClass{
//这是一个方法,`MyClass::foo`
公共静态整数foo(整数a、整数b){
返回a*b;
}
//这是一个包含函数“MyClass.bar”的字段`
公共静态ToIntBiFunction bar=(整数a、整数b)->{
返回a*b;
};
}

testclass
中没有方法
multi(…)
。您在
ImageConvertor
@Turing85中有一个静态字段
multi
,这是我的错误我复制了错误的名称,现在我修复了它您使用的是in
ddd
的类型定义(
ToIntBiFunction
应该是
ToIntBiFunction
)。另外,为了避免不必要的强制转换,
testclass
中的方法
multi
应该返回
int
而不是
Integer
@Turing85感谢您更改为“双函数尝试更改公共静态intmulti(inta,intb){返回a*b;}到testclass,然后使用testclass::multit,我得到了相同的结果error@eyalmazuz我不能用我没见过的代码来解决新问题。@eyalmazuz当然可以。同样地,
testclass::multi
意味着类
testclass
有一个方法
multi
。但是您有一个类型为
到intbifunction
的字段。
testclass::multit
class MyClass {
    // This is a method, `MyClass::foo`
    public static Integer foo(Integer a, Integer b) {
        return a*b;
    }
    // This is a field holding a function, `MyClass.bar`
    public static ToIntBiFunction<Integer, Integer> bar = (Integer a,Integer b)-> {
        return a*b;
    };
}