Bug 66424

Summary: [1.5] Collections in new style for loop
Product: [Eclipse Project] JDT Reporter: Rob Dingwell <bobd>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.0   
Target Milestone: 3.1 M1   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

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.