Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jdt-core-dev] Problem with generics, Map.Entry

Hi,

I'm using Eclipse 3.1M1 and i'm getting the same error. But if I import java.util.Map.Entry then the error goes away.

e.g.:

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

public class CheetahBug {
  public static void main(String[] args) {
     Map<String, String> map = new HashMap<String, String>();
map.put("foo", "bar"); Iterator<Entry<String,String>> i = map.entrySet().iterator();
     while (i.hasNext()) {
        Entry<String, String> entry = i.next();
        System.out.println(entry.getKey() + ", " + entry.getValue());
     }
  }
}

Regards,
Eyðun

David Hovemeyer wrote:

Howdy,

Please accept my apologies if this is the wrong mailing list,
or if this is a known problem.

I'm using Eclipse 3.0 with the org.eclipse.jdt.core and
org.eclipse.jdt.ui plugins upgraded to HEAD, and the
org.eclipse.jdt.debug plugin upgraded to JDK_1_5.  (I built these
yesterday.)  My hope is to be able to use Eclipse to work on a
fairly large project that uses generics, but no other 1.5 language
features.

Almost all of the project built fine within Eclipse (!).  However,
I'm getting compile errors in places where entrySet().iterator()
is called on a Map with type parameters.  The following
code (which compiles fine using 1.5 beta2 javac) demonstrates the
problem:

package edu.umd.cs.daveho;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class CheetahBug {
	public static void main(String[] args) {
		Map<String, String> map = new HashMap<String, String>();
		
		map.put("foo", "bar");
		
		// Error reported on the following line
		Iterator<Map.Entry<String,String>> i = map.entrySet().iterator();
		while (i.hasNext()) {
			Map.Entry<String, String> entry = i.next();
			System.out.println(entry.getKey() + ", " + entry.getValue());
		}
	}
}

There are a few other places where Eclipse flags errors on things
that compile fine in 1.5.  I'll try to distill these as small test
cases.

-Dave
_______________________________________________
jdt-core-dev mailing list
jdt-core-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/jdt-core-dev



Back to the top