Skip to content


JSR335: Functional Interfaces

August 12, 2013

This post is the start of a 9 part series on JSR 335. Part 1 of 9 – Functional Interfaces.

functional interface is an interface that has just one abstract method. In addition to the one abstract method, an interface is still functional if it contains any number or combination of default and/or static methods. Also, if any of the abstract methods in the interface are implemented by java.lang.Object, this does NOT count as an abstract method. Obviously, since abstract methods must be public when implemented by a class, only the public methods on java.lang.Object qualify for this rule.

In addition to instantiating a class that implements that interface, functional interfaces can be created with lambda expressions, method references, or constructor references.

java.lang.FunctionalInterface is a runtime, type annotation to indicate the annotated interface is meant to be a functional interface. If the annotated interface does not qualify as functional, then it’s a javac compile time error. Below is an example of the javac error if an interface “SomeInterface” is annotated with @FunctionalInterface but does not meet the definition of a functional interface.

SomeInterface is not a functional interface
multiple non-overriding abstract methods found in interface SomeInterface

NOTE: if an interface meets the criteria of a functional interface, then the compiler will treat it as a FunctionalInterface whether the annotation is present or not.

Examples from JLS 8 – Functional Interfaces and Descriptors


From → Java

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: