InnerClass
needs to be static
itself, i.e.
public class Test {
static class InnerClass{
}
public static void main(String[] args){
InnerClass ic = new InnerClass();
}
}
If InnerClass
is not static
, it can only be instantiated in the context of a parent instance of Test
. The rather baroque syntax for this is:
public class Test {
class InnerClass{
}
public static void main(String[] args){
Test test = new Test();
InnerClass ic = test.new InnerClass();
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…