Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 473353

Summary: Java 8 map functionality does not work when using ternary operator in return clause
Product: [Eclipse Project] JDT Reporter: Michael Strasser <mistrasser1>
Component: CoreAssignee: Sasikanth Bharadwaj <sasikanth.bharadwaj>
Status: VERIFIED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: jarthana, manoj.palat, sasikanth.bharadwaj
Version: 4.5   
Target Milestone: 4.6 M1   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Michael Strasser CLA 2015-07-23 03:44:27 EDT
Hi,

when I am using the new map-functionality of Java 8 and I return a string, it works like a charme if I directly return a String like here:

new TreeSet<String>().stream().
                    map(l -> {
                        String prefix = (true) ? "a" : "b";

                        return  prefix;
                    }).
                    collect(Collectors.joining(","));


However, if I do not use the variable and directly return the result of the ternary operator, like below, I get a compilation error in eclipse:

new TreeSet<String>().stream().
                    map(l -> {
                        return  (true) ? "a" : "b";
                    }).
                    collect(Collectors.joining(","));


The compilation error states: The method collect(Collector<? super Object,A,R>) in the type Stream<Object> is not applicable for the arguments (Collector<CharSequence,capture#10-of ?,String>)


Both variants work with the normal Java compiler outside of Eclipse.
Comment 1 Sasikanth Bharadwaj CLA 2015-07-23 05:00:20 EDT
Not reproducible on master. Fixed via changes for bug 463728

*** This bug has been marked as a duplicate of bug 463728 ***
Comment 2 Jay Arthanareeswaran CLA 2015-08-04 02:43:30 EDT
Verified for 4.6 M1 with build I20150803-2000.