| Summary: | [1.5] Type mismatch: cannot convert from Maybe<capture#2-of ? extends U> to Maybe<U> | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Michal Svoboda <svobomic> |
| Component: | Core | Assignee: | Stephan Herrmann <stephan.herrmann> |
| Status: | VERIFIED WONTFIX | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | jarthana, mat.gessel+eclipse, Olivier_Thomann, stephan.herrmann |
| Version: | 3.7 | ||
| Target Milestone: | 4.14 M3 | ||
| Hardware: | PC | ||
| OS: | Linux | ||
| Whiteboard: | |||
Simplified (somewhat) case:
import java.util.Collections;
import java.util.List;
public class Generics {
public List<Generics> something(List<? extends Generics> c) {
return Collections.singletonList(c.get(0));
}
}
The code is equivalent to the following one (local variable introduced), which causes no error in eclipse.
public List<Generics> something(List<? extends Generics> c) {
Generics o = c.get(0);
return Collections.singletonList(o);
}
Version from Help:
Version: Helios Service Release 2
Build id: 20110218-0911
Problem still exists at 1.7, but at 1.8 ecj compiles this just fine. Both code examples work for me in JDT 3.18.100.v20190916-1045 (In reply to Mat Gessel from comment #3) > Both code examples work for me in JDT 3.18.100.v20190916-1045 thanks for retesting. Let's be honest: - at compliance 1.7- ecj still reports an error, but not at 1.8 and greater - we don't have plans to fix this kind of 1.7-only problem, we can't even be sure the spec of that version positively covers this case. Verified for 4.14 M3 using build I20191119-1250 |
Build Identifier: 3.7 M5 I got the following piece of code, that compiles with javac, but in eclipse IDE it shows the error message "Type mismatch: cannot convert from Maybe<capture#2-of ? extends U> to Maybe<U>" at the marked line. public abstract class Maybe<T> { public static <T> Maybe<T> definitely(final T theValue) { return new DefiniteValue<T>(theValue); } public abstract <U> Maybe<U> to(Function<? super T, ? extends U> mapping); private static class DefiniteValue<T> extends Maybe<T> { private final T theValue; public DefiniteValue(T theValue) { this.theValue = theValue; } @Override public <U> Maybe<U> to(Function<? super T, ? extends U> mapping) { return definitely(mapping.apply(theValue)); // ERROR! } } public static interface Function<F, T> { T apply(F input); } } Reproducible: Always