Skip to main content

Why aren't functional interfaces allowed on annotation type elements?

No replies
steffenyount
Offline
Joined: 2008-11-27
Points: 0

I’m designing a utility to do declarative object mapping + data binding using simple POJOs.

I was surprised to find out that annotation type elements were not updated to allow functional interface types in Java 8.

Q1: Was this an oversight?

Q2: Is there a technical reason why annotation type elements were not extended to allow functional interfaces for Java 8?

Q3: Is there a technical reason why the compiler could’t support this?

Ideally I would be able to used compiler-checked method references to declare my getter and setter bindings using only annotated POJO fields.

I would expect any of the following values would be valid values for an annotation element with a functional interface type:

a lambda expression
a method reference to a Static Method
a method reference to an Instance Method of an Arbitrary Object of a Particular Type
a method reference to an Instance Method of a Particular Enum Object
a method reference to a Constructor

Meanwhile I’d expect that method references requiring a non-Enum Object instance would not be supported.