@Test public void testHandleMethodFromObject() { DeepThoughtAsync async = createAsync(); DeepThoughtSync sync = SyncClientAdapterHandler.newHandler(DeepThoughtSync.class, DeepThoughtAsync.class, async); assertThat(sync.hashCode()).isEqualTo(async.hashCode()); }
private Object handleMethodFromObject(Method method, Object[] args) throws IllegalAccessException, InvocationTargetException { if (METHOD_EQUALS.equals(method.getName())) { Object other = args[0]; if (!Proxy.isProxyClass(other.getClass())) { return false; } InvocationHandler otherHandler = Proxy.getInvocationHandler(other); return otherHandler instanceof SyncClientAdapterHandler && ((SyncClientAdapterHandler) otherHandler).delegate == delegate; } else { return method.invoke(delegate, args); } }
SyncClientAdapterHandler implements InvocationHandler { private Object handleMethodFromObject(Method method, Object[] args) throws IllegalAccessException, InvocationTargetException { if (METHOD_EQUALS.equals(method.getName())) { Object other = args[0]; if (!Proxy.isProxyClass(other.getClass())) { return false; } InvocationHandler otherHandler = Proxy.getInvocationHandler(other); return otherHandler instanceof SyncClientAdapterHandler && ((SyncClientAdapterHandler) otherHandler).delegate == delegate; } else { return method.invoke(delegate, args); } } }
SyncClientAdapterHandler implements InvocationHandler { private Object handleMethodFromObject(Method method, Object[] args) throws IllegalAccessException, InvocationTargetException { if (METHOD_EQUALS.equals(method.getName())) { Object other = args[0]; if (!Proxy.isProxyClass(other.getClass())) { return false; } InvocationHandler otherHandler = Proxy.getInvocationHandler(other); return otherHandler instanceof SyncClientAdapterHandler && ((SyncClientAdapterHandler) otherHandler).delegate == delegate; } else { return method.invoke(delegate, args); } } private  SyncClientAdapterHandler(Class<?> asyncIfcClass, Object delegate); }
SyncClientAdapterHandler implements InvocationHandler { private Object handleMethodFromObject(Method method, Object[] args) throws IllegalAccessException, InvocationTargetException { if (METHOD_EQUALS.equals(method.getName())) { Object other = args[0]; if (!Proxy.isProxyClass(other.getClass())) { return false; } InvocationHandler otherHandler = Proxy.getInvocationHandler(other); return otherHandler instanceof SyncClientAdapterHandler && ((SyncClientAdapterHandler) otherHandler).delegate == delegate; } else { return method.invoke(delegate, args); } } private  SyncClientAdapterHandler(Class<?> asyncIfcClass, Object delegate); static S newHandler(Class<? extends S> syncIfcClass, Class<? super A> asyncIfcClass,
                                      A delegateAdapter); @Override Object invoke(Object proxy, Method method, Object[] args); }
SyncClientAdapterHandler implements InvocationHandler { private Object handleMethodFromObject(Method method, Object[] args) throws IllegalAccessException, InvocationTargetException { if (METHOD_EQUALS.equals(method.getName())) { Object other = args[0]; if (!Proxy.isProxyClass(other.getClass())) { return false; } InvocationHandler otherHandler = Proxy.getInvocationHandler(other); return otherHandler instanceof SyncClientAdapterHandler && ((SyncClientAdapterHandler) otherHandler).delegate == delegate; } else { return method.invoke(delegate, args); } } private  SyncClientAdapterHandler(Class<?> asyncIfcClass, Object delegate); static S newHandler(Class<? extends S> syncIfcClass, Class<? super A> asyncIfcClass,
                                      A delegateAdapter); @Override Object invoke(Object proxy, Method method, Object[] args);  }