Skip to main content

Why is a functional interface with a generic method not allowed?

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2005-07-20

When trying to use a functional interface that has a generic method javac complains that the method is generic. However I can't find anything about that in the specification? In fact the specification contains the following example of a functional interface, but it does not compile when used:

interface Executor { T execute(Action a); }

This I used as follows:

abstract class Action {
abstract T invoke();
Executor e = (a) -> System.out.println(a.invoke());

But javac (from build 1.8.0-ea-b123) complains:

incompatible types: invalid functional descriptor for lambda expression
method (test.domain.Action)T in interface test.domain.Executor is generic

Can anybody explain why a generic method is not allowed in a functional interface, or point me to the relevant earlier discussion or documentation?


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2014-03-14

Generic types need to bedefined and they are also parameters (not at runtime but at compile time it is the invoker who defines the actual type).
Executor doesn't need a type argument as it just runs a runnable and that returns nothing (it is void). But that is only true for java.util.concurrent.Executor.
You didn't specify what test.domain.Executor does.