是stated那:
A static nested class interacts with the instance members of its outer class (and other classes) just like any other top-level class. In effect, a static nested class is behaviorally a top-level class that has been nested in another top-level class for packaging convenience.
那么如何解释这个静态嵌套类可以访问其封闭类的私有(private)构造函数呢?
最佳答案
So how to explain this static nested class has access to private constructor of its enclosing class?
因为任何
private
的范围和可访问性成员(字段、构造函数或方法)是其声明类的完整主体,包括任何嵌套类。来自 Java Language Specification section 6.6.1 :
if the member or constructor is declared
private
, then access is permitted if and only if it occurs within the body of the top level class (§7.6) that encloses the declaration of the member or constructor.
关于java - 静态嵌套类可以访问外部类的私有(private)构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23111745/