Static method returning inner class
问题 I really don't understand why the getMyClass2 method below cannot be static, why isn't it valid Java code? public class MyClass { private class MyClass2 { public String s1 = ""; public String s2 = ""; } private MyClass2 myClass2; private static MyClass2 getMyClass2() { MyClass2 myClass2 = new MyClass2(); return myClass2; } public MyClass() { myClass2 = getMyClass2(); } } 回答1: You have to say that the inner class is static because non-static is bound to the instance so it cannot be returned