

import JavaGroups.MethodCall;
import JavaGroups.MethodLookup;
import JavaGroups.MethodLookupClos;


    
class A {
    void foo() {System.out.println("A.foo()");}
}

class B extends A {
    void foo() {System.out.println("B.foo()");}
}



public class MethodCallTest {


    public void PrintFoo(A a) {
	System.out.println("PrintFoo(A a)");
	a.foo();
    }


    public void PrintFoo(B b) {
	System.out.println("PrintFoo(B b)");
	b.foo();
    }


    public void ThrowException() throws Exception {
	throw new Exception("This is an exception thrown by ThrowException()");
    }


    public int Add(int x, int y) {
	return x+y;
    }

    public int Add(int x, long y) {
    	return 22;
    }

    public int Add(int x, byte y) {
	return 55;
    }

    public int Add(int x, short y) {
	return 99;
    }

    
    public int Add(long x, int y) {
    	return 44;
    }
    
    public int Add(long x, long y) {
    	return 66;
    }
    



    public static void main(String args[]) {
	MethodCall      m;
	MethodCallTest  test=new MethodCallTest();
	MethodLookup    lookup=new MethodLookupClos();

	try {
	    // m=new MethodCall("Add", new Integer(22), new Short((short)24));
	    m=new MethodCall("ThrowException");
	    //System.out.println(m.Invoke(test, null));
	    Object retval=m.Invoke(test, lookup);
	    System.out.println("retval is " + retval);

	    //long a=3, b=4;
	    //System.out.println(test.Add(a, (int)b));
	}
	catch(Exception e) {
	    System.err.println("Caught and exception: " + e);
	}
    }
}
