How to do it...

Follow these steps to learn how to use lambda expressions:

  1. Let's start building an API. We will call it Traffic. Without using functional interfaces, it might look like this:
public interface Traffic {   void speedAfterStart(double timeSec, int trafficUnitsNumber);}  

Its implementation may be as follows:

public class TrafficImpl implements Traffic {   private int hour;   private Month month;   private DayOfWeek dayOfWeek;   private String country, city, trafficLight;   public TrafficImpl(Month month, DayOfWeek dayOfWeek, int hour,                 String country, String city, String trafficLight){      this.hour = hour;      this.city = city;      this.month = month;      this.country = country;      this.dayOfWeek = dayOfWeek;      this.trafficLight = trafficLight;   } public void ...

Get Java 11 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.