Bug 520799 - [1.8][inference] lambda compile error
Summary: [1.8][inference] lambda compile error
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.8   Edit
Hardware: PC Windows 7
: P3 major with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: helpwanted
Depends on:
Blocks: 564617
  Show dependency tree
 
Reported: 2017-08-10 03:10 EDT by pepa zdepa CLA
Modified: 2023-01-22 17:09 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description pepa zdepa CLA 2017-08-10 03:10:18 EDT
Following code ends up with compilation errors:

//----------------
Future<Runnable> fut = executorService.submit( () -> {
			// do some calculations here and then
			// return a lambda that will do something after           		
			return () -> {
				try {
					// do after job here
				} catch (Exception e) {
					String msg = "some error message";
					logger.warn(msg, e);
				}
			};
        });
//---------------

On first lambda (Callable) I got the error message:
The method submit(Callable<T>) in the type ExecutorService is not applicable for the arguments (() -> {})
On second lambda (Runnable) is compilation error:
The target type of this expression must be a functional interface
Comment 1 Stephan Herrmann CLA 2017-08-11 13:29:30 EDT
In the past we learned that JLS alone doesn't always cope well with nested lambdas, and additional advice from javac developers was needed to improve ecj in this regard.

Will be a hard nut to crack.

Workaround: pass an explicit type argument:

 ... executorService.<Runnable>submit( ...
Comment 2 Manoj N Palat CLA 2018-05-17 03:26:01 EDT
bulk move out of 4.8
Comment 3 Manoj N Palat CLA 2018-08-16 00:06:46 EDT
Bulk move out of 4.9
Comment 4 Mat Gessel CLA 2019-11-03 01:13:31 EST
Works for me in 2019-09 R (4.13.0) • JDT 3.18.100.v20190916-1045 • tried ecj 1.8, 12. Stubbed out test case follows:


//----------------
import java.util.concurrent.Callable;
import java.util.concurrent.Future;

public class _520799
{
    class StubExecutorService
    {
        public <T> Future<T> submit(Callable<T> task)
        {
            return null;
        }
    }
    
    void test()
    {
        StubExecutorService es = new StubExecutorService();
        Future<Runnable> fut = es.submit(() -> {
            // do work here
            return () -> {
                // called after complete
            };
        });
    }
}
//----------------
Comment 5 Eclipse Genie CLA 2023-01-22 17:09:16 EST
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.

If you have further information on the current state of the bug, please add it. 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.