Concept: Type checking in java 8 lambdas is done based on target (the function to which it is being passed as an argument).
Explanation: Generally a function is defined by 3 attributes:
- Function Name.
- Type and order of arguments passed.
- Return type of function.
But while passing an lambda Java only checks for last two. So for above Functional Interface we need lambda with [first] argument type MyFunctional and return type void.
void doSomething(MyFunctional x) { ... ... x.invokeSame(...An object/lambda of type MyFunctional...) } To call this function doSomething(varName -> { ...someCode... })