-
1. Problem with equals/hashCode?
jgarrison Jan 20, 2011 2:52 PM (in response to jgarrison)Better implementation of getRealDeclaringClass()
private Class<?> getRealDeclaringClass(Method m) throws NoSuchMethodException
{
// Get the method's current declaring class
Class<?> dcl = m.getDeclaringClass();
// Special handling for equals and hashCode() -- first unmangle the name
String name = m.getName().contains("equals") ? "equals" : m.getName().contains("hashCode") ? "hashCode" : null;
if (name != null)
{
// Walk up the class hierarchy to the first non-proxy class
while(dcl.getName().contains("javassist"))
dcl = dcl.getSuperclass();
// Now get the declaring class of the unmangled name
dcl = dcl.getMethod(name,m.getParameterTypes()).getDeclaringClass();
}
return dcl;
}