Applying method and constructor references
Some of the lambda expressions can be simplified using some valid short-hand forms, given that a certain method or keyword can satisfy the implementation of the concerned functional interfaces. Instead of writing the full-blown expressions with the parameters and curly braces, we intend to reduce lambda expression as much as possible to apply the principles of functional programming. This recipe will highlight how to optimize a lambda expression used in object instantiation and method calls.
Getting started
Open the same project, ch06
, and let us implement service classes that utilize built-in functional interfaces using method and constructor references.
How to do it...
To illustrate the use of method and constructor references, follow these steps:
- Create a service implementation named
EmployeeDataService
, which will provide instances of emptyEmployee
instances and a zero-sizedArrayList
object for a list of employees. Also, it has a method that converts...