JBoss Community

Re: Problem with equals/hashCode?

created by James Garrison in Javassist - View the full discussion

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;

        }

Reply to this message by going to Community

Start a new discussion in Javassist at Community