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

Getting ready

Any interface that has one and only one abstract method is called a functional interface. To help avoid a runtime error, the @FunctionalInterface annotation was introduced in Java 8 that tells the compiler about the intent. In our demo code in the previous chapters, we've already had an example of a functional interface:

public interface SpeedModel {  double getSpeedMph(double timeSec,   int weightPounds, int horsePower);  enum DrivingCondition {    ROAD_CONDITION,    TIRE_CONDITION  }  enum RoadCondition {    //...  }  enum TireCondition {    //...  }}

The presence of enum types or any implemented (default or static) methods does not make it a non-functional interface. Only abstract (not implemented) methods count. So, this is an example of a ...

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