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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.