Can't replace SAM-constructor with lambda when first argument is a class with one method
I found a rule in compiler: if Java-method call requires types which is SAM-interfaces, then you can replace them with lambdas (or functions), but either all such parameters, or none of them.
So, you have method: public void observe(OneMethod one, Observer<T> observer)
.
Both parameters is SAM candidates. You can call:
observer(object1, object2)
or:
observer(function1, function2)
but not:
observer(object1, function2)
and not:
observer(function1, object2)
Same behaviour will be even in case of 3 or more parameters. The cause of this is technical difficulty in compiler design.
Sorry if I am not very clear, I'm not very good in English.