Created
December 14, 2014 13:27
-
-
Save bbq2100/c5d2a0ab3066c79f3960 to your computer and use it in GitHub Desktop.
Old but gold since JDK 1.3^^
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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