Bug 66424 - [1.5] Collections in new style for loop
Summary: [1.5] Collections in new style for loop
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.1 M1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-06-09 17:25 EDT by Rob Dingwell CLA
Modified: 2005-01-11 11:02 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rob Dingwell CLA 2004-06-09 17:25:44 EDT
When working with a Hashtable and a new style for loop the editor is confused
about the correct type of the Hashtables key and values sets. In the simple
example below the editor states a type mismatch cannot convert Integer to
String. Change the String s to Integer s, the editor complains that it cannot
convert String to Integer.

The same holds true for other Collection classes as well. In the example code
the same cannot covert from type Integer to String occures when using the list
in the for loop.

I imagine this has something to do with the JavaModel being used in the editor
as they are only visual errors and the class compiles and runs ok.


public class test {

	public static void main(String[] args) { 
	    Hashtable<Integer, String> h = new Hashtable<Integer,String>(); 
	    h.put(new Integer(0), "value"); 
	    String st = h.get(new Integer(0));
	    
	    for(String s:  h.values()){
	    	System.out.println(s);
	    }
            
            List<String> l = new ArrayList<String>();

	    for(String s:  l){
	    	System.out.println(s);
	    }


	  }
}
Comment 1 Rob Dingwell CLA 2004-06-09 17:32:02 EDT
Playing around a bit more this seams to happen sporadically when initially
creating a class and editing it. If you close the editor and reopen the error
markers are gone. 
Comment 2 Philipe Mulet CLA 2004-06-09 19:35:34 EDT
You guessed right, this is due to the model not yet knowing about generics and 
thus fooling the editor. When you build however, the compiler has no issue 
with these, and this explains why you don't see markers persisted in problem 
view. 

These inconsistencies are temporary. As soon as support is added to the model, 
these should disappear. FYI, we are working on adding this support at the 
moment, and will refresh the Cheetah as soon as we can finalize it.
Comment 3 Philipe Mulet CLA 2004-06-28 09:40:28 EDT
Support released in JavaModel for generics. Testcase is no longer reporting 
problems in editor.