Nested/Inner class in external file

后端 未结 6 696
醉话见心
醉话见心 2021-01-07 15:57

I have a class MyClass and an inner class MyNestedClass like this:

public class MyClass {
  ...
  public class MyNestedClass {
             


        
6条回答
  •  执笔经年
    2021-01-07 16:42

    Objects of inner classes keep implicit references to the objects of the paren class. If the nested class is not static (it is inner) you can not. But if the nested class does not need access to the parent's class instances directly and does not need access to the private fields, than should be ok to refactor, move the inner class out and do not declare it public (out of that package can not be accessed).

提交回复
热议问题