I'm trying to understand functional interfaces and lambda functions.And I can't find an explanation of how a function in a functional interface connects it with a lambda function , that is, let's say there is such a functional interface
@FunctionalInterface
interface MyPredicate {
boolean test(Integer value);
}
and now we assign the variables of the functional interface to the lambda function:
public class Tester {
public static void main(String[] args) throws Exception {
MyPredicate myPredicate = x -> x > 0;
System.out.println(myPredicate.test(10)); //true
}
}
I'm exactly wondering why when calling myPredicate.test(10)
a call is being made x > 0
.
That is, do I understand correctly that when we assign a lambda function, the compiler somehow connects the function from the functional interface with the body of the lambda function?it's just that inheritance and override are usually used for this ,but here the compiler does it or how?I will be glad to have explanations to understand this issue