import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; public class DemoProxy { public static void main(String[] args) { Class iface = DemoProxyFunction.class; ClassLoader loader = DemoProxyFunction.class.getClassLoader(); InvocationHandler handler = new SomeHandler(); DemoProxyFunction function = (DemoProxyFunction) Proxy.newProxyInstance(loader, new Class[] { iface }, handler); System.out.println("output value " + function.evaluate(5, 10)); } static class SomeHandler implements InvocationHandler { public Object invoke(Object arg0, Method method, Object[] args) throws Throwable { if ((Integer.class.equals(method.getReturnType())) && (args.length == 2) && (args[0] instanceof Integer) && (args[1] instanceof Integer)) return null; int value1 = ((Integer) args[0]).intValue(); int value2 = ((Integer) args[1]).intValue(); return new Integer(value1 + value2); } } }