Can an annotation type be a functional interface?
Markus Keller
markus_keller at ch.ibm.com
Tue Dec 3 05:19:33 PST 2013
[sending to lambda-spec-comment & lambda-spec-observers]
Can an annotation type (JLS7 9.6) be a functional interface (jsr335-0.7.0
9.8)?
The current spec just says "A functional interface is an interface that
[...]". JLS7 9 defines the term "interface" as applicable to normal
interfaces as well as annotation types. Therefore, this snippet should
compile without errors:
//javac 1.8.0-ea-b115 error: Unexpected @FunctionalInterface annotation
@FunctionalInterface
@interface I { }
public class Test {
// javac error: incompatible types: I is not a functional interface
I i= () -> I.class;
// OK. Abstract method: Class<? extends Annotation> annotationType()
java.lang.annotation.Annotation a= () -> I.class;
}
But since it hardly makes sense to use a marker annotation type as a
functional interface, I actually agree with javac. The jsr335 spec should
be fixed.
More information about the lambda-spec-comments
mailing list