public Object invoke(Object proxy, Method m, Object[] args) throws Throwable { Object result; try { String methodName = m.getName(); if (send_to_first.contains(methodName)) { return m.invoke(first, args); } else if (send_to_second.contains(methodName)) { return m.invoke(second, args); } else { Class[] parameterTypes = m.getParameterTypes(); Method rm = getClass().getMethod(methodName, parameterTypes); return rm.invoke(this, args); } } catch (InvocationTargetException e) { throw e.getTargetException(); } }