> -----Original Message-----
> From: Takuya Murata [mailto:[EMAIL PROTECTED]
> Sent: 20 August 2003 11:55
> To: Jakarta Commons Developers List
> Subject: Re: [collections] Questions....
>
> A tricky situation is
>
> class A {
> public void method (Iterator i);
> public void method (ListIterator i);
> };
>
> new A ().method (new SingletonIterator ());
Such methods are somewhat dangerous since lots of people may assume that the
virtual method invocation applies to the argument as well as the object the
method is being invoked on. This is not the case it is a pure compile time
dependency so whatever it is cast as it what get's used. This is a common
problem with people thinking they are overriding Object#equals(Object o) by
writing
...
public boolean equals(MyClass c)
{
...
}
when they are only adding an overloaded method and HashMap for example will
not make use of the method...
In this case ListIterator extends Iterator which means that the will be no
compile time complaints it will just always go with ListIterator since it
searches top down.
Obviously in the hands of a skilled java OO coder these present no probs and
may allow an elegant solution, but exposing them as a public API should be
done with care.
Matt
**************************************************************************
The information transmitted herewith is sensitive information intended only
for use by the individual or entity to which it is addressed. If the reader
of this message is not the intended recipient, you are hereby notified that
any review, retransmission, dissemination, distribution, copying or other
use of, or taking of any action in reliance upon this information is
strictly prohibited. If you have received this communication in error,
please contact the sender and delete the material from your computer.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]