Dain Sundstrom wrote:

On Wednesday, March 26, 2003, at 09:29 PM, Victor Langelo wrote:


I haven't read Effective Java, but this won't work for us. We intentionally create derived primary key classes for each entity. These are derived from generic pk classes when the primary key data is a simple primative type. The super class implements equals, compareTo and hashCode. I don't see any reason these would need to be reimplemented in each derived class.


The purpose of the derived classes is primarly for type safety.

I should have added that our client side framework depends on there being different classes for each domain type. For instance if you double click on a refund in a list of transactions we need to know to open the form for editing/viewing a refund instead of one for editing payments.


I loaned my copy of Effective Java to a friend so I can't quote. The basic idea is that if a.equals(b) is true b.equals(a) must also be true. This means you must test for the exact type of the related compare to object. You must have code that looks something like this.


public boolean equals(object o)
{
   if(o instanceof MyType)
   {
      return value.equals((MyType).value);
   }
   return false;
}

The important part is the instance of check. I suppose you could do this check with reflection... something like this

if(getClass() == o.getClass())

Agreed. We do something similar. Due to class loader issues, it isn't always that simple :(



So I guess you are right, but we know that if one of the super classes (other then Object) we know that the implementation is wrong.

I sorry, but I don't understand this statement at all.



public static boolean definesEquals(Class clazz)
{
   Class[] params = new Class[] { Object.class };

   while (clazz != null && !clazz.equals(Object.class)) {
      try {
         Method m = clazz.getDeclaredMethod("equals",  params);
         if (m.getReturnType() == Integer.TYPE)
            return true;
      } catch (NoSuchMethodException) {
      }
      clazz = clazz.getSuperclass();
   }
   return false;
}


That should work.

-dain

--Victor




-------------------------------------------------------
This SF.net email is sponsored by:
The Definitive IT and Networking Event. Be There!
NetWorld+Interop Las Vegas 2003 -- Register today!
http://ads.sourceforge.net/cgi-bin/redirect.pl?keyn0001en
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to