5

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 ...


4

One of the interesting things added to java in v8 is functional interfaces. Previously java only matched things up and verified correctness by type (type names). With functional interfaces, java now looks at the structure of code in certain situations. I can add examples to this answer to clarify if anyone asks. One interesting feature you can add is a ...


4

One site that I find helpful for basic examples of coding task written in a multitude of programming languages is RosettaCode. While it is not always a win when going there, I still keep it high on the list of sites to check when looking for teaching examples or code that demonstrates something. In this case the combination of the programming language ...


2

I think the most critical thing about lambda functions is that they enable the convenient use of map and filter functions on collections and streams. Exercises in using these (and their equivalents in Optional, which is perhaps just as important, allowing us to get rid of null as it does) are probably the best way of showing what you can achieve with lambda ...


2

One idea might be to borrow SQL-related exercises -- find problems asking the reader to come up with some sort of SQL query to find information, and rephrase the problem and ask students to come up with an equivalent query using only Java's functional interface and lambda expressions. (I wouldn't bother telling students these questions were originally about ...


1

A second example of fairly simple lambda expressions that lets you delve into some interesting side discussions is the problem of reversing a linked list in linear time. It is easy to use list 'head', 'tail', and 'cons' to write a method, putlast, that puts the head of a list at its tail, removing it from the head, but otherwise leaving the elements intact....


Only top voted, non community-wiki answers of a minimum length are eligible