All pastes #372950 Raw Edit

Anonymous

public text v1 · immutable
#372950 ·published 2007-02-26 12:27 UTC
rendered paste body
import java.lang.reflect.Method;
import java.lang.Class;

interface I{
    public void hello();
}
class A implements I{
    public void hello(){
	System.out.println("hello");
    }
}

class B{
    public void call_hello(I i){
	i.hello();
    }
}

public class testCase{
    public static void main(String[] args) {
	try{
	    String methodName = "call_hello";
	    B b = new B();
	    A a = new A();
	    Class c = B.class;
	    Class[] parameterTypes = new Class[] {A.class};
	    Method m = c.getMethod(methodName, parameterTypes);
	    m.invoke(b, new Object[] {a});
	} catch (Exception e){
	    e.printStackTrace();
	}
    }
}