Monday, February 17, 2014

Java 8 Lambdas - The Unintentional Puzzle

I was tinkering with Java 8 lambdas just lately. It happened to be an early morning on a bus from Tallinn to Tartu and I probably didn't sleep enough the night before. So I managed to puzzle myself with this little piece of code:

I actually expected it to print "Hello, lambda!" when executed, but it didn't. Can you figure out why? This is a very simple puzzler, and a very silly mistake that I did. I shouldn't have used the method reference to initialize the runner variable of RunForrestRun class. However, while the example is very simple, it actually shows that the new features do bring some accidental complexity into the language.

1 comment:

Rrr said...

Great Talk