harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tony Wu" <wuyue...@gmail.com>
Subject Re: [classlib][luni] A problem about behavior of EnumMap
Date Tue, 29 Aug 2006 15:52:28 GMT
I found all of the previous entrys will be set to current one while
iter.next() was invoked. so I guess there is just the same instance returned
by iter.next() with variable modifications.
It is a bug if not a trade-off for performance I think.

On 8/28/06, Spark Shen <smallsmallorgan@gmail.com> wrote:
>
> Hi All:
> When I develop EnumMap,I find EnumMap strange on RI. As the following
> code describes, the method entrySet() of
> EnumMap returns a set view of mappings contained in this map. Then we
> get the set's iterator and use the iterator's next() method to get an
> Entry which contains one mapping. But if we use next() method again to
> get another Entry, the previous Entry will also point to the next Entry.
>
> import java.util.EnumMap;
> import java.util.Iterator;
> import java.util.Map;
> import java.util.Set;
>
> import junit.framework.TestCase;
>
> public class EnumMapTest extends TestCase{
>    enum Size {
>        Small, Middle, Big {
>        };
>    }
>    public void test_entrySet() {
>        EnumMap enumSizeMap = new EnumMap(Size.class);
>        enumSizeMap.put(Size.Middle, 1);
>        enumSizeMap.put(Size.Big, null);
>
>        Set set = enumSizeMap.entrySet();
>        Iterator iter = set.iterator();
>        Map.Entry entry = (Map.Entry) iter.next();
>        assertEquals(Size.Middle, entry.getKey());
>        Map.Entry entry1 = (Map.Entry) iter.next();
>        assertEquals(Size.Big, entry.getKey());
>        assertSame(entry,entry1);
>    }
> }
> I guess on RI, the returned iterator maintains a reference to current
> entry and returns this reference in iter.next() method.
> I do not think RI's  behavior makes sense here. So I suggest not to
> follow RI on the behavior.
>
> Best regards
>
> --
> Spark Shen
> China Software Development Lab, IBM
>
>
> ---------------------------------------------------------------------
> Terms of use : http://incubator.apache.org/harmony/mailing.html
> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>
>


-- 
Tony Wu
China Software Development Lab, IBM

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message