Below code working
Function fun1= super::equals Function fun2= Object::hashCode
But below code is not
Function fun1= Object::equals Function fun2= super::hashCode
What is the concept here even though all are instance methods in Object class.
I have read somewhere the principals are:
- object::instance methods
- Class::static method
- Class:: instance Method
Function interface is a functional interfaces representing a function that accepts one parameter and returns a value.
super::equals works because it is a function that accepts one parameter and returns a value.
Object::equals does not work because it is a function that accepts two parameters and returns a value.
If you have a method reference of the form
ClassName::instanceMethod, the function that it represents will have an extra parameter - the object on which to call the method. According to the docs:
The equivalent lambda expression for the method reference
String::compareToIgnoreCasewould have the formal parameter list
(String a, String b), where
bare arbitrary names used to better describe this example. The method reference would invoke the method
super::equals is of the form
instance::instanceMethod so there is no problem and works as you expect.
The correct functional interface types to use for
BiFunction<Object, Object, Boolean> and
Also, don't use raw types.