I don't understand why line #3 is compiling without any problem. There is only one execute() method in ExecutorService which takes a Runnable, and Runnable run() returns void.
Line #3 shouldn't compile because toString() has an incompatible return type. But it does.
Line #4 does not compile, the compiler error is: bad return type in Lambda expression.
Thank you, Juerg
Functional interfaces that have a void return type can always be implemented by lambda expressions that have a statement as their body. Even if that statement is a method call with a return type, the return type is simply ignored.
#3 compiles because rid.toString() is a statement.
#4 does not compile because "TestRiddle" is not a statement.
For the same reason, you can do this:
And not this:
The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.