harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rachel Chen" <reche...@gmail.com>
Subject Re: [classlib] HashMap
Date Fri, 21 Sep 2007 11:58:42 GMT
Hi , Sian
Thank you for your suggestion. But I still don't understand.
Yes, It seems the entries are instances of HashMap.Entry
But I traced the code. Here is how the iterator comes: Iterator<?> iterator
= entrySet().iterator();
public Set<Map.Entry<K, V>> entrySet() {
        return new HashMapEntrySet<K, V>(this);
    }
public Iterator<Map.Entry<KT, VT>> iterator() {
            return new HashMapIterator<Map.Entry<KT, VT>, KT, VT>(
                    new MapEntry.Type<Map.Entry<KT, VT>, KT, VT>() {
                        public Map.Entry<KT, VT> get(MapEntry<KT, VT> entry)
{
                            return entry;
                        }
                    }, associatedMap);
        }
So I don't know why it is necessary to use Entry<?, ?> entry = (Entry<?, ?>)
iterator.next(),why can not Map.Entry<?,?>
Thanks.

On 9/21/07, Sian January <sianjanuary@googlemail.com> wrote:
>
> Hi Rachel,
>
> From looking at HashMap it looks it depends on the fact that the entries
> are
> instances of HashMap.Entry (i.e. by using the 'next' field), so it's not
> just as simple as changing the type to be Map.Entry.  It would require
> quite
> a lot of changes to HashMap so I think it might be easier to fix in
> common-chain (e.g. by overriding the writeObject method), unless anyone
> thinks that HashMap is designed to be extended in this way, in which case
> we
> should fix it in Harmony.
>
> Thanks,
>
> Sian
>
>
> On 21/09/2007, Rachel Chen <rechel88@gmail.com> wrote:
> >
> > Hello,
> > I got a exception when I run test common-chain which is also a project
> > under
> > ASF.
> > I found out that is how it happens: We have a interface Map.Entry and
> > Class
> > MapEntry implements Map.Entry and a inner class of HashMap called Entry
> > extends MapEntry. Here comes the problem: a class in common-chain called
> > ContextBase extends HashMap and one of its inner classes
> > MapEntryImpl implement Map.Entry. When ContextBase call a method
> > writeObject in HashMap which has such a clause Entry<?, ?> entry =
> > (Entry<?,
> > ?>) iterator.next(), stream goes back to ContextBase and returns like
> this
> > Map.Entry entry= ContextBase.this.entry(keys.next())(this one is a
> > MapEntryImpl).
> > To fix this bug, Can I just simply modify  Entry<?, ?> entry = (Entry<?,
> > ?>)
> > iterator.next() to Map.Entry<?,?>=(Map.Entry<?, ?>) iterator.next()
?
> > Any comments and suggestion? Thank you.
> >
>
>
>
> --
> Unless stated otherwise above:
> IBM United Kingdom Limited - Registered in England and Wales with number
> 741598.
> Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU
>

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