【发布时间】:2015-11-10 12:58:34
【问题描述】:
如何从 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的实例,因为它是一个实例方法...... -
或将
Private和Private.getMeSomething()设为静态。
标签: java reflection inner-classes