On Thu, 21 Feb 2002, Leo Sutic wrote:
>
>
> > From: Antti Koivunen [mailto:[EMAIL PROTECTED]]
> >
> > I've seen this happen, but people who implement equals() should know
> > better :)
>
> And given pooling of components, and the standard usage patterns, and
> the fact that you should only call the methods specified in the
> component's interface (do not call Object methods), I agree.
>
> /LS
It may be a more common situation than you think. If you put your proxy
object in a Collection and call Collection.contains(proxy) it will fail
even though the proxy is in the Collection. This is because Object.equals
is called under the covers and gets forwarded to the delegate by the
invocation handler (unless of course you handle these Object methods
specially by your invocation handler.)
The pattern I've seen used for this is
Object invoke(Object proxy, Method method, Object[] args) {
if (method.getDeclaringClass() == Object.class) {
return method.invoke(proxy, args);
}
// delegate your interface methods
// ...
}
Regards,
--mike
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>