如何从主方法访问内部类的 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));
}
关于java - JAVA中如何访问私有(private)内部类的私有(private)参数化方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33630585/