Mark Wielaard wrote:
> On Fri, 2005-12-16 at 20:22 +0100, Wolfgang Baer wrote:
> > + /**
> > + * Tests if the given object is equal to this object.
> > + * The objects are considered equal if both are of the same
> > + * Media subclass, not null and the values are equal.
> > + *
> > + * @param obj the object to test
> > + *
> > + * @return <code>true</code> if both objects are equal,
> > + * <code>false</code> otherwise.
> > + */
> > + public boolean equals(Object obj)
> > + {
> > + if ((obj instanceof MediaName && this instanceof MediaName)
> > + || (obj instanceof MediaTray && this instanceof MediaTray)
> > + || (obj instanceof MediaSizeName && this instanceof MediaSizeName))
> > + {
> > + return ((Media) obj).getValue() == this.getValue();
> > + }
> > +
> > + return false;
> > + }
>
> Wouldn't it be a bit more robust to write this as:
>
> return (obj.getClass() == this.getClass()
> && ((Media) obj).getValue() == this.getValue());
>
> Then you also accept any future subclasses.Except when obj == null. Then it's less robust. -- Chris Burdess "They that can give up essential liberty to obtain a little safety deserve neither liberty nor safety." - Benjamin Franklin
pgpyNHqVWgFe6.pgp
Description: PGP signature
_______________________________________________ Classpath-patches mailing list [email protected] http://lists.gnu.org/mailman/listinfo/classpath-patches
