Implementing lambda expression using @FunctionInterface
Java 1.8 has formalized the lambda expression implementation through the use of the @FunctionalInterface
annotation and the inclusion of the new specification on anonymous functions. This recipe will open a new technique in creating lambda expression.
Getting started
Using the same Eclipse project and EmployeeServiceImpl
, add the needed service methods using @FunctionInterface
components.
How to do it...
Many of the API classes in Java 1.8 use functional interfaces to simplify service implementation by applying the principles of functional programming. To illustrate what functional programming is, let us implement the following steps:
- Create another version of the
EmployeeRecord
interface of the previous recipe that uses the@FunctionalInterface
annotation:
@FunctionalInterface public interface EmployeeRecordService { public List<Employee> getEmployees(); }
- Also in
org.packt.function.codes.service
, create a functional interface...