O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.month = month;            this.dayOfWeek = dayOfWeek;            this.hour = hour;            this.country = country;            this.city = city;            this.trafficLight = trafficLight;          } public ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required