Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 422596

Summary: [1.8][compiler][spec] Can an annotation type be a functional interface?
Product: [Eclipse Project] JDT Reporter: Markus Keller <markus.kell.r>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: srikanth_sankaran, stephan.herrmann
Version: 4.4   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard: stalebug

Description Markus Keller CLA 2013-11-26 12:14:48 EST
Srikanth, I think this needs to be taken to the 335 EG.

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 [...]", and since JLS7 9 defines the term "interface" as applicable to normal interfaces as well as annotation types, 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 as a functional interface, I actually agree with javac. The jsr335 spec should be fixed.
Comment 2 Srikanth Sankaran CLA 2014-01-31 17:56:05 EST
We will watch this space for changes and react when called for. Adjusted
target accordingly.
Comment 3 Markus Keller CLA 2014-02-19 06:39:12 EST
Considered a bug in javac: https://bugs.openjdk.java.net/browse/JDK-8030663
Comment 4 Eclipse Genie CLA 2020-05-17 17:11:29 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 5 Stephan Herrmann CLA 2020-05-17 17:20:19 EDT
https://bugs.openjdk.java.net/browse/JDK-8030663 acknowledges that javac violates JLS, but neither wants to move. => No need for action for ecj either.