classpath-patches
[Top][All Lists]
Advanced

[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: Wolfgang Baer
Subject: Re: [cp-patches] FYI: Patch for EnumSyntax attributes in the print api
Date: Mon, 19 Dec 2005 09:26:33 +0100
User-agent: Debian Thunderbird 1.0.7 (X11/20051017)

Chris Burdess wrote:
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.

Yes, it might be null. Also I don't think there will be more
subclasses in the future except the IPP standard will be extended.

Marc, I can use your way with an additional null check if you
prefer ?

if (obj == null)
  return false;

return (obj.getClass() == this.getClass()
        && ((Media) obj).getValue() == this.getValue());

Wolfgang





reply via email to

[Prev in Thread] Current Thread [Next in Thread]