From markus_keller at ch.ibm.com Tue Dec 3 02:11:55 2013 From: markus_keller at ch.ibm.com (Markus Keller) Date: Tue, 3 Dec 2013 11:11:55 +0100 Subject: Self-reference to field from lambda expression in initializer Message-ID: JLS7 8.3.2.3 "Restrictions on the use of Fields during Initialization" says as point 4: "C is the innermost class or interface enclosing the usage". This should be expanded to include lambda bodies, e.g.: "C is the innermost class or interface enclosing the usage, or the usage occurs inside a lambda expression body that occurs in the initializer". The informative text later in that section confirms this intention: "The restrictions above are designed to catch, at compile time, circular or otherwise malformed initializations." In case of lambda bodies, self-references don't cause malformed initializations, so this restriction is not necessary. It would make sense to handle self-references in lambda expressions the same as in anonymous classes. Example that shows that javac only disallows unqualified access as per 8.3.2.3: public class C { // javac 1.8.0-ea-b115 says: error: self-reference in initializer Runnable i= () -> executeAndRepost(i); static Runnable s= () -> executeAndRepost(s); // OK: Runnable qi= () -> executeAndRepost(this.qi); static Runnable qs= () -> executeAndRepost(C.qs); Runnable a= new Runnable() { @Override public void run() { executeAndRepost(a); } }; static void executeAndRepost(Runnable r) { } } From markus_keller at ch.ibm.com Tue Dec 3 05:19:33 2013 From: markus_keller at ch.ibm.com (Markus Keller) Date: Tue, 3 Dec 2013 14:19:33 +0100 Subject: Can an annotation type be a functional interface? Message-ID: [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 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.