September 2018
Intermediate to advanced
802 pages
19h 30m
English
Any interface that has one and only one abstract method is called a functional interface. To help avoid a runtime error, the @FunctionalInterface annotation can be added in front of the interface. It tells the compiler about the intent, so the compiler can check to see whether there is actually one abstract method in that interface, including those inherited from other interfaces.
In our demo code in the previous chapters, we've already had an example of a functional interface, even if we did not annotate it as functional:
public interface SpeedModel { double getSpeedMph(double timeSec, int weightPounds, int horsePower); enum DrivingCondition { ROAD_CONDITION, TIRE_CONDITION } enum RoadCondition { //... } enum TireCondition ...Read now
Unlock full access