Bug 72644 - [1.5] Problems with generic maps
Summary: [1.5] Problems with generic maps
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Linux
: P3 normal with 1 vote (vote)
Target Milestone: 3.1 M2   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 73608 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-08-25 17:19 EDT by Marco Qualizza CLA
Modified: 2004-09-24 06:01 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marco Qualizza CLA 2004-08-25 17:19:31 EDT
I don't know if these problems arise from a misunderstanding on my part, or if
it's a problem with Eclipse.  Everything that I have been able to find indicates
that I'm on the right track.  The code is at the end of the report.

1. I've implemented a Map, and I'm having problems with the #entrySet method. 
The message I get (from Eclipse) is: "Type mismatch: Cannot convert from
Set<Map<K,V>.Entry<String, V> to Set<Map.Entry<String, V>>"  (javac has no problem)

2. Javac 1.5.0-beta2 complains "GenericMap.java:7: test.GenericMap is not
abstract and does not override abstract method putAll(java.util.Map<? extends
java.lang.String,? extends V>) in java.util.Map
public class GenericMap<V> implements Map<String, V> {"  while Eclipse accepts
the class.


package test;

import java.util.Collection;
import java.util.Map;
import java.util.Set;

public class GenericMap<V> implements Map<String, V> {
   private Map<String, V> backingMap;
   
   public int size() { return 0; }

   public boolean isEmpty() { return false; }

   public boolean containsKey(Object key) { return false; }

   public boolean containsValue(Object value) { return false; }

   public V get(Object key) { return null; }

   public V put(String key, V value) { return null; }

   public V remove(Object key) { return null; }

   public void clear() { }

   public Set<String> keySet() { return null; }

   public Collection<V> values() { return null; }


   public void putAll(Map<String, ? extends V> t) { }

  
   public Set<Map.Entry<String, V>> entrySet() {
      return this.backingMap.entrySet();
   }
}
Comment 1 Marco Qualizza CLA 2004-08-25 17:21:05 EDT
The line in #entrySet that causes the problem is "return
this.backingMap.entrySet();"
Comment 2 Marco Qualizza CLA 2004-08-31 13:55:45 EDT
Re: the first problem.

If you define #entrySet() as:
public Set<Entry<String, V>> entrySet() {
   return backingMap.entrySet();
}

(ie/ you're not specifying Map.Entry, you're only saying Entry)
Then your error message turns into:
"Type mismatch: cannot convert from Set<Map<K,V>.Entry<String,V>> to
Set<Map<String,V>.Entry<String,V>>"
Comment 3 Kent Johnson CLA 2004-09-09 16:47:37 EDT
*** Bug 73608 has been marked as a duplicate of this bug. ***
Comment 4 Michael McDougall CLA 2004-09-09 17:03:45 EDT
I was able to work around bug73608 using non-generic types and a cast. Not
pretty, but ok for now.
Comment 5 Philipe Mulet CLA 2004-09-18 08:24:07 EDT
There was a problem constructed binding for parameterized static member types, 
resulting in non comparable types being built.

Fixed in latest, added regression tests: GenericTypeTest#test297 & test298.
Comment 6 Frederic Fusier CLA 2004-09-24 06:01:14 EDT
Verified that problem 1 is fixed for 3.1 M2 with build I200409231635.

I'll open a other bug for problem 2 (putAll overriding not warned) which is
still not fixed.