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

In the cases, when a one-line lambda expression consists of a reference to an existing method only (implemented somewhere else), it is possible to further simplify the notation using the method reference. The reference method can be static or non-static (the latter can be bound to a particular object or not) or can be a constructor with or without parameters.

The syntax of the method reference is Location::methodName, where Location indicates where (in which object or class) the methodName method can be found. The two colons (::) serve as a separator between the location and the method name. If there are several methods with the same name at the specified location (because of the method overload), the reference method is identified ...

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