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 13:01:03 GMT
Hi, Sian
I am sorry that I didn't make myself clear enough in the first mail.
When the exception happens here, it says MapEntryImpl is incompatiable with
HashMap.MapEntry
Because in these clause Entry<?, ?> entry = (Entry<?, ?>) iterator.next(),
it returns a MapEntryImpl  which can not be assigned to Entry<?,?>. Since:
HashMap.Entry extends MapEntry, MapEntry implements Map.Entry
MapEntryImpl implements Map.Entry


On 9/21/07, Sian January <sianjanuary@googlemail.com> wrote:
>
> Hi Rachel,
>
> Sorry - you mentioned the writeObject method, so I assumed that's where
> the
> exception was being thrown from.  Is it actually coming from the iterator
> method?  It would be helpful if you could post a stack trace.  Even so, I
> think if we did change the iterator method you might have problems
> elsewhere
> in the class, but it's difficult to say without knowing what exactly the
> exception is.
>
> Thanks,
>
> Sian
>
>
> On 21/09/2007, Rachel Chen <rechel88@gmail.com> wrote:
> >
> > 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.Entryand
> > > > 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
> > >
> >
>
>
>
> --
> 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