import java.lang.reflect.Proxy; public class Main public static void main(String[] args) RealUserService realService = new RealUserService();
Cache Method objects in a HashMap inside your handler to avoid repeated method.invoke() resolution. 7. Beyond JDK Proxies: CGLIB and Byte Buddy The JDK's reflect 4 proxy has one major limitation: it can only proxy interfaces . If you need to proxy a concrete class (without interfaces), you must use bytecode generation libraries.
import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; public class LoggingHandler implements InvocationHandler private final Object target; // real object
public interface InvocationHandler public Object invoke(Object proxy, Method method, Object[] args) throws Throwable;