public class Test {
public static void main(String[] args)throws Exception{
Outer outer = new Outer();
//获取内部类对象
Object object = outer.outerfuc();
Method method = object.getClass().getMethod("innerfuc");
method.invoke(object);
}
class Outer {
public Object outerfuc(){
int x = 6;
class Inner{
public void innerfuc(){
System.out.println(x);
}
}
Inner inner = new Inner();
inner.innerfuc();
return inner;
}
}