private Method cacheMethod( Object obj, String methodName, Class[] methodParameters, HashMap methodCache) { Class objClass = obj.getClass(); Method objMethod = null; // Look up inheritance hierarchy while (objClass != Object.class) { try { objMethod = objClass.getDeclaredMethod(methodName, methodParameters); objClass = Object.class; // executed only if call succeeds } catch (NoSuchMethodException nsmE) { objClass = objClass.getSuperclass(); } } // Cache result if (objMethod == null) { methodCache.put(obj.getClass(), NONE); } else { objMethod.setAccessible(true); // monstrous, monstrous methodCache.put(obj.getClass(), objMethod); } return objMethod; }