Lambda as constructor argument (javac bug?)

Mark Mahieu markmahieu at gmail.com
Tue Nov 9 19:11:59 PST 2010


Hi,

Should lambdas be allowed in the context of a constructor invocation?  The latest SotL discusses lambda conversion w.r.t. method invocation, which I'd assumed applies also to constructors, but javac seems to be stricter about this:

	class UnexpectedLambda {
		
		public static void main(String[] args) {
			expect(#{});  // ok
			new UnexpectedLambda(#{});  // rejected
		}

		static void expect(Runnable r) {}

		UnexpectedLambda(Runnable r) {}
	}


	$ javac UnexpectedLambda.java
	UnexpectedLambda.java:5: lambda expression not expected here
       	        new UnexpectedLambda(#{}); // rejected
                 	                   ^
	1 error


Regards,

Mark


More information about the lambda-dev mailing list