Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 318433 - [infer type arguments] "Infer generic type..." refactoring doesn't infer generic type argument for Iterator
Summary: [infer type arguments] "Infer generic type..." refactoring doesn't infer gene...
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.6   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
: 229842 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-06-30 06:25 EDT by Andrew Kowal CLA
Modified: 2019-08-20 13:24 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Kowal CLA 2010-06-30 06:25:26 EDT
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.
Comment 1 Dani Megert CLA 2010-07-28 10:41:55 EDT
Can be reproduce using R3.6.
Comment 2 Dani Megert CLA 2010-07-28 10:42:15 EDT
*** Bug 229842 has been marked as a duplicate of this bug. ***
Comment 3 Markus Keller CLA 2010-10-19 13:07:18 EDT
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);
        }
    }
}
Comment 4 Markus Keller CLA 2010-12-15 10:29:53 EST
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.
Comment 5 Eclipse Genie CLA 2019-08-20 13:24:16 EDT
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.