The Artima Developer Community
Sponsored Link

Legacy Design Forum
Canonical Object Idiom

Advertisement

Advertisement

This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

avoir le code de calcul

Posted by Mouloud Idiri on December 30, 2001 at 7:04 AM

> Hi!

> The code for equals() in the article ensures that the Object passed as an argument is of the same type as itself by trying a typecast; failure results in a ClassCastException which is caught:

> public boolean equals(Object o) {

> if (o == null) {
> return false;
> }

> Worker w;
> try {
> w = (Worker) o;
> }
> catch (ClassCastException e) {
> return false;
> }
> .
> .
> .

>
> I saw this simpler code elsewhere:

> public boolean equals(Object obj)
> {
> if (obj != null && (obj instanceof this.getClass()))
> {
> .
> .
> .

> Is this OK? Or are there any hidden glitches in this that aren't apparent to me?

> Thanks,
> Vijay






Replies:
  • fgf sdf December 30, 2001 at 7:06 AM (0)

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us