A functional interface is simply an interface with only one non-default, non-static method. All interfaces that satisfy that definition can be implemented through a lambda in Java 8.
For example, Runnable
is a functional interface and in Java 8 you can write: Runnable r = () -> doSomething();
.
Many of the functional interfaces brought by Java 8 are in the java.util.function
package. The most common are:
Consumer<T>
which has avoid accept(T t)
Supplier<T>
which has aT get()
Function<T, R>
which has aR apply(T t)
Predicate<T>
which as aboolean test(T t)
What you could do at this stage is to use single method interfaces wherever it makes sense, if possible with similar signatures. When you migrate to Java 8 you will be able to easily refactor through your IDE from:
someMethod(new MyConsumer<T>() { public void accept(T t) { use(t); } });
into
someMethod(t -> use(t));
Then change the signature of someMethod(MyConsumer<T> mc)
into someMethod(Consumer<T> c)
, get rid of you MyConsumer
interface and you are done.