Java 8 allows method references to be used instead of lambda expressions in many situations. A method reference provides a streamlined way of invoking an implementation of a functional interface. In this tutorial, you will write a method reference as an alternative to a lambda implementation of a greeting interface.
System.outand it is separated from the class by double semicolons (
::). The method reference is passed to the
sendGreetingmethod as the implementation of the functional interface
Consumeris one of the functional interfaces provided by Java 8. It contains the method
acceptthat has one argument of the generic type specified on the
Consumerdeclaration (line 8). In this case, the type is
String. The lambda implementation is on line 5. Observe that the method reference requires less code than the lambda expression.