Summary: | Cast to generic type within "for" iterator no longer works under 3.1RC2 | ||
---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | David Pickens <pickens> |
Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> |
Status: | RESOLVED INVALID | QA Contact: | |
Severity: | normal | ||
Priority: | P3 | CC: | cdsmith |
Version: | 3.1 | ||
Target Milestone: | 3.1 RC3 | ||
Hardware: | PC | ||
OS: | Windows XP | ||
Whiteboard: |
Description
David Pickens
2005-06-15 14:47:54 EDT
M6 was too permissive. We now flag an error, and javac agrees with us. Our compiler was incorrectly using type expectation from cast to drive inference, which is against the spec. So really, if the spec was changing we would revert to old behavior. Write instead: import java.util.ArrayList; import java.util.List; public class Test1 { static <T> List<T> foo() { return new ArrayList<T>(); } public static void main(String[] args) { List<String> foo = foo(); for (String s: foo) {} } } *** Bug 100879 has been marked as a duplicate of this bug. *** |