After some email with Bill, it looks like we can use Class.getDeclaredMethods to find which method the class implements (you learn something new every day). It specifically excludes inherited methods, so we can use it to verify if a primary key has actually implemented hashCode and equals.

Since equals equals is not really inheritable (see Effective Java), I think we should throw a verifier error if a pk does not directly implement it. HashCode on the other hand can be inherited (and still be valid), so I think we should only print a warning if they don't directly. We could check the parents until we get to Object to see if they left the default implementation.

Who maintains the verifier?

-dain

Here is the code I wrote in to test this:

   public static boolean definesEquals(Class clazz)
   {
      Method[] method = clazz.getDeclaredMethods();
      for(int i=0; i<method.length; i++)
      {
         if(method[i].getName().equals("equals") &&
               method[i].getParameterTypes().length == 1 &&
               method[i].getParameterTypes()[0] == Object.class &&
               method[i].getReturnType() == Boolean.TYPE)
         {
            return true;
         }
      }
      return false;
   }
   public static boolean definesHashCode(Class clazz)
   {
      Method[] method = clazz.getDeclaredMethods();
      for(int i=0; i<method.length; i++)
      {
         if(method[i].getName().equals("hashCode") &&
               method[i].getParameterTypes().length == 0 &&
               method[i].getReturnType() == Integer.TYPE)
         {
            return true;
         }
      }
      return false;
   }



-------------------------------------------------------
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