Lambda conversion in Method invocation context
Arul Dhesiaseelan
aruld at acm.org
Fri Nov 12 09:42:48 PST 2010
Hi Maurizio,
Thanks for the clarification. The new error message is much better and
clarifies the intent.
-Arul
On Fri, Nov 12, 2010 at 2:28 AM, Maurizio Cimadamore <
maurizio.cimadamore at oracle.com> wrote:
> On 12/11/10 07:11, Peter Levart wrote:
> > 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
> >
> >
> The semi-colon should not represent a problem. The real problem is that
> the call is ambiguous: ExecutorService defines two methods called
> 'submit', one accepting Callable(T) and another one accepting a
> Runnable. Both target methods are compatible with a lambda whose type is
> 'void()'.
>
> The error message is weird because the prototype has some problems
> related to error recovery during overload resolution (which I'm trying
> to fix) - the version I'm working on emits this error:
>
> /home/maurizio/Desktop/Inference.java:6: reference to submit is
> ambiguous, both method <T>submit(Callable<T>) in ExecutorService and
> method submit(Runnable) in ExecutorService match
> e.submit(#{System.out.println("Processing a short-lived asynchronous
> task.")});//fails
> ^
> where T is a type-variable:
> T extends Object declared in method <T>submit(Callable<T>)
> 1 error
>
> Which does a better job at explaining what's wrong.
>
> Maurizio
>
>
--
http://aruld.info
http://twitter.com/aruld
More information about the lambda-dev
mailing list