package org.itstack.demo.desgin.factory; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Proxy; public class JDKProxy { public static T getProxy(Class interfaceClass, ICacheAdapter cacheAdapter) throws Exception { InvocationHandler handler = new JDKInvocationHandler(cacheAdapter); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Class[] classes = interfaceClass.getInterfaces(); return (T) Proxy.newProxyInstance(classLoader, new Class[]{classes[0]}, handler); } }