如何从main方法访问Inner类的getMeSomething方法?我所需要的只是能够发送一个整数并在main方法中获得返回值。
public class OuterClass {
public static void main(String[] args) {
//Using Java Reflection...I tried to create an inner class Object
//created a outer class object
//and invoke the method without any success
}
static class Inner {
private class Private {
private int getMeSomething(int num) {
return (num*2);
}
}
}//end of inner class
} //end of outer class
您需要一个Inner和Private:的实例
public static void main(String[] args) {
//Using Java Reflection...I tried to create an inner class Object
//created a outer class object
//and invoke the method without any success
Private p = new Inner ().new Private ();
System.out.println(""+p.getMeSomething(21));
}