I'm currently started to learn Lambda Expressions in Java and I'm trying to figure out why this code doesn't work I have a general class:
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;
}
}
and the main in another class
public class ImageCovertor{
public static void main (String[] args) throws IOException {
int d;
testclass test = new testclass();
BiFunction<ToIntBiFunction,Integer, Integer> ddd = (ToIntBiFunction fn, Integer a)->{
return fn.applyAsInt(a,a);
};
d= ddd.apply(testclass::multit, 5);
System.out.println(d);
}//end of main
public static ToIntBiFunction<Integer,Integer> multit = (Integer a,Integer b)->{
return a*b;
};
}
and I'm trying to pass the multit as a parameter in the ddd lambda fuction but this like of code gives me an error:
d= ddd.apply(testclass::multit, 5);
The type testclass does not define multit(Object, Object) that is applicable here
also tried to make the function in the main but it gives me the same error the code works when I write
testclass.multit
instead of
testclass::multit
can someone explain to me why the second one doesn't work and how to fix this? thank you