如何使用 JAVA 中的静态 class 访问私有内部 class 的私有参数化方法
How to Access private parameterized method of private inner class with in a static class in JAVA
如何从 main 方法访问 Inner class 的 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));
}
如何从 main 方法访问 Inner class 的 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));
}