![](/img/trans.png)
[英]java - reflection: How to Override private static abstract inner class method?
[英]How to Access private parameterized method of private inner class with in a static class in JAVA
如何从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));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.