O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Getting ready

The examples in the previous recipe (that used anonymous classes for functional interfaces' implementation) looked bulky and felt excessively verbose. For one, there was no need to repeat the interface name because we had declared it already as the type for the object reference. Second, in the case of a functional interface (that had only one abstract method), there was no need to specify the method name to be implemented. The compiler and Java runtime can figure it out anyway. All we needed was to provide the new functionality. This is where a lambda expression comes to the rescue. 

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required