When you have -> , the javac compiler adds a static method with the contents of the code. It also adds dynamic call information to the class, so the JVM can display the interface that the lambda implements for the arguments and return type. The JVM generates code at run time to bind the interface to the generated method.
The difference with lambdas and anonymous classes is that the implict variables should only be final (as it could be final), and the member variables are copied, that is, they do not retain the reference to this external class.
It can tell the difference between Runnable and Callable<void> , although both arguments do not accept. For more details http://vanillajava.blogspot.com/2014/09/lambdas-and-side-effects.html
source share