summaryrefslogtreecommitdiff
path: root/libjava/testsuite/libjava.lang/ProxyTest.java
blob: 46689b43a9d81a43af52d31d128bf988c2da24fd (plain)
1
2
3
4
5
6
7
8
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
37
import java.lang.reflect.*;

interface Twas
{
  Object brillig();
}

interface Slithy
{
  void toves(int gyre);
}

public class ProxyTest
{
  static class MyInvocationHandler implements InvocationHandler
  {
    public Object invoke(Object proxy, Method method, Object[] args)
    {
      System.out.println (method.getDeclaringClass());
      System.out.println (args == null
			  ? args
			  : args.getClass().getName());
      return this;
    }
  }

  public static void main(String[] argv)
    throws InstantiationException, IllegalAccessException
  {
    Twas wabe
      = (Twas)Proxy.newProxyInstance(ProxyTest.class.getClassLoader(),
				     new Class[] { Slithy.class, Twas.class },
				     new MyInvocationHandler());
    wabe.brillig();
    ((Slithy)wabe).toves(2);
  }
}