How to explain lambda expressions This year I will teach students about lambda expressions (in java). I am trying to explain how they are interpreted by the JVM and what they unfold into.

For example:

String firstString = "this is a lambda example!";
String secondString = "and we compare to this, as well";
Function&lt;String, Double&gt; comparison = (String third) -&gt;
        (third.compareTo(firstString) + third.compareTo(secondString)) / 2.0;


would create a function that gives the average of the comparison between a given string and firstString and secondString. I've tried to explain to a selection of students (as a Proof of Concept of my planned lesson, so only 4-5 students) that lambda expressions just make things look better but they think that it's a new way to do this. I am trying to explain that lambda expressions are simply a shortened way to write something a bit bigger.

So my question is, how do I explain what lambda expressions exactly are, in such a way that shows the students how these expressions are interpreted by Java?
A lambda is an anonymous function.  Java handles lambdas via a feat of type inference.  What you have done is to assign a lambda to a variable of interface type. You may only do this if the interface is a functional interface, i.e., it is an interface that specifies exactly one [non-defaullt] method.

When you do this assignment, the compiler assumes that the lambda is the method specified by the interface that is they type of the variable.  It is here that type inference occurs.  An object of unnamed type implementing the interface is crated and your variable now points at it.  The compiler will reject your code if the argument list or return type of the lambda is incompatible with the interface.  

You will find lambdas to be splendid if you are doing event-driven programming.  In fact the JavaFX framework takes big advantage of this feature.