1. Use the @FunctionalInterface Annotation
Today's tips is to annotate a functional interface with the
@FunctionalInterface
annotation thereby signaling that API users may use lambdas to implement the interface. It also ensures that the interface remains usable for lambdas over time by preventing abstract methods from accidentally being added to the API later on.Do This:
@FunctionalInterface
public interface CircleSegmentConstructor {
CircleSegment apply(Point cntr, Point p, double ang);
// abstract methods cannot be added
}
Don't Do This:
public interface CircleSegmentConstructor {
CircleSegment apply(Point cntr, Point p, double ang);
// abstract methods may be accidentally added later
}
Read more in the original article at https://dzone.com/articles/the-java-8-api-design-principles
Follow the Java Holiday Calendar 2016 with small tips and tricks all the way through the winter holiday season.