Community
Participate
Working Groups
Build Identifier: 20100617-1415 Having code below, try to infer Iterator's generic type argument via Quick fix. public class Test { public static void main(String[] args) { Map<String, Long> myMap = new HashMap<String, Long>(); for (Iterator it = myMap.entrySet().iterator(); it.hasNext(); ) { System.out.println(it); } } } Reproducible: Always Steps to Reproduce: 1. Take the code mentioned in bug details. 2. Try to infer generic type argument via quick fix for Iterator 3. Ensure refactoring doesn't make any changes, i.e. doesn't work.
Can be reproduce using R3.6.
*** Bug 229842 has been marked as a duplicate of this bug. ***
import java.util.*; import java.util.Map.Entry; public class Try { // infers nothing for Iterator and Entry: void foo(HashMap<String, Integer> map) { for (Iterator iter = map.entrySet().iterator(); iter.hasNext();) { Entry entry = (Entry) iter.next(); System.out.println((String) entry.getKey() + (Integer) entry.getValue()); } } // correctly infers arguments for Iterator, but not for Entry: void foo2(HashMap<String, Integer> map) { Set<Entry<String, Integer>> entrySet = map.entrySet(); for (Iterator iter = entrySet.iterator(); iter.hasNext();) { Entry entry = (Entry) iter.next(); System.out.println((String) entry.getKey() + (Integer) entry.getValue()); } } // works: void bar(List<String> list) { for (Iterator iter = list.iterator(); iter.hasNext();) { String string = (String) iter.next(); System.out.println(string); } } }
Already doesn't work for simple chains like t.getList().iterator(): import java.util.*; public class Try2 { void test(Try2 t) { for (Iterator iter = t.getList().iterator(); iter.hasNext();) { String s = (String) iter.next(); System.out.println(s); } } public List<String> getList() { return new ArrayList<String>(); } } But it does work when the return type of getList() is the raw type List (and not List<String>). Tentatively targeting M5.
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.