@Test public void testAdapt() { Interface1 interface1 = Prodigy.adapt(new Impl1()); Interface2 interface2 = (Interface2) interface1; interface2.toString(); try { Impl1 impl1 = Prodigy.adapt(new Impl1()); impl1.toString(); fail(); } catch (ClassCastException e) {} }
@SuppressWarnings("unchecked") public static <T> T adapt(T target) { List<Class<?>> interfaces = ClassUtils.getAllInterfaces(target.getClass()); Object proxy = Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces.toArray(new Class[] {}), new ClientInvocationHandler(target)); try { T client = (T) proxy; return client; } catch (ClassCastException e) { throw new IllegalArgumentException("Specified target must be an interface type", e); } }
Prodigy { @SuppressWarnings("unchecked") public static <T> T adapt(T target) { List<Class<?>> interfaces = ClassUtils.getAllInterfaces(target.getClass()); Object proxy = Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces.toArray(new Class[] {}), new ClientInvocationHandler(target)); try { T client = (T) proxy; return client; } catch (ClassCastException e) { throw new IllegalArgumentException("Specified target must be an interface type", e); } } }
Prodigy { @SuppressWarnings("unchecked") public static <T> T adapt(T target) { List<Class<?>> interfaces = ClassUtils.getAllInterfaces(target.getClass()); Object proxy = Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces.toArray(new Class[] {}), new ClientInvocationHandler(target)); try { T client = (T) proxy; return client; } catch (ClassCastException e) { throw new IllegalArgumentException("Specified target must be an interface type", e); } } private  Prodigy(); }
Prodigy { @SuppressWarnings("unchecked") public static <T> T adapt(T target) { List<Class<?>> interfaces = ClassUtils.getAllInterfaces(target.getClass()); Object proxy = Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces.toArray(new Class[] {}), new ClientInvocationHandler(target)); try { T client = (T) proxy; return client; } catch (ClassCastException e) { throw new IllegalArgumentException("Specified target must be an interface type", e); } } private  Prodigy(); @SuppressWarnings("unchecked") static T adapt(T target); static String inject(String name, String params); static void eject(String id); static Map<String, Class<? extends Fault>> faults(); static Entry status(String id); static List<Entry> status(); static void push(String name, InputStream jar); }
Prodigy { @SuppressWarnings("unchecked") public static <T> T adapt(T target) { List<Class<?>> interfaces = ClassUtils.getAllInterfaces(target.getClass()); Object proxy = Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces.toArray(new Class[] {}), new ClientInvocationHandler(target)); try { T client = (T) proxy; return client; } catch (ClassCastException e) { throw new IllegalArgumentException("Specified target must be an interface type", e); } } private  Prodigy(); @SuppressWarnings("unchecked") static T adapt(T target); static String inject(String name, String params); static void eject(String id); static Map<String, Class<? extends Fault>> faults(); static Entry status(String id); static List<Entry> status(); static void push(String name, InputStream jar);  }