TestProxy.java 774 Bytes
Newer Older
1 2 3
import java.lang.reflect.Proxy;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
Anthony Green committed
4 5 6 7
import java.net.*;

public class TestProxy
{
8
  public static class MyInvocationHandler implements InvocationHandler
Anthony Green committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
  {
    public Object invoke (Object proxy,
			  Method method,
			  Object[] args)
      throws Throwable
    {
      System.out.println (args[0]);
      return null;
    }
  }

  public static void main (String[] args)
  {
    try {
      InvocationHandler ih = new MyInvocationHandler();
      
      SocketOptions c = (SocketOptions)
	Proxy.newProxyInstance (SocketOptions.class.getClassLoader(),
				new Class[]{SocketOptions.class},
				ih);
      
      c.getOption (555);

    } catch (Exception e) {
      e.printStackTrace ();
    }
  }
}