Category: Java 常见问题
静态内部类,非静态内部类
We recently have used SonarQube to do the code coverage. And when I checked the issue Sonar gave. I found that I have to learn more about the static nested class and non-static nested classes.
If you define the following class.
class OuterClass {
...
class InnerClass {
...
}
}
特性:
- The instance of InnerClass can only exist within the instance of OuterClass
- the OuterClass has direct access to the methods and fields of its inner instance.
- If you want to instantiate an inner class, you must instantiate the outer class.