[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [cp-patches] FYI: Patch for EnumSyntax attributes in the print api
From: |
Chris Burdess |
Subject: |
Re: [cp-patches] FYI: Patch for EnumSyntax attributes in the print api |
Date: |
Sun, 18 Dec 2005 22:12:23 +0000 |
User-agent: |
Mutt/1.5.10i |
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
pgpNPxXIGoqB7.pgp
Description: PGP signature