Skip to content

Instantly share code, notes, and snippets.

@bbq2100
Created December 14, 2014 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbq2100/c5d2a0ab3066c79f3960 to your computer and use it in GitHub Desktop.
Save bbq2100/c5d2a0ab3066c79f3960 to your computer and use it in GitHub Desktop.
Old but gold since JDK 1.3^^
package App;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
public class Main {
public static void main(String[] args) {
MyInvocationHandler handler = new MyInvocationHandler();
MyProxy proxy = (MyProxy) Proxy.newProxyInstance(MyProxy.class.getClassLoader(), new Class[]{MyProxy.class}, handler);
System.out.println(proxy.getAnswer());
}
private static class MyInvocationHandler implements InvocationHandler {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return 42;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment