Lambda conversion in Method invocation context

Peter Levart peter.levart at marand.si
Thu Nov 11 23:11:07 PST 2010


On 11/12/10, Arul Dhesiaseelan wrote:
> Hi,
> 
> I get the following compile error when I use a lambda in a method invocation
> context:
> 
> SimpleRunnable.java:14: internal error; cannot instantiate println(String)
> at ExecutorService to (<>#void())
>                 executor.submit(#{System.out.println("Processing a
> short-lived asynchronous task.")});
>                                ^
> 1 error
> 

I think, you're trying to write this:

executor.submit( 
  #{ System.out.println("Processing a short-lived asynchronous task."); }
);

...note the semicolon after println method invocation. Invocation of a void method can not be used as expression.

Javac error is somewhat strange though.

Peter


More information about the lambda-dev mailing list