静态嵌套类可以访问外部类的私有构造函数 [英] Static nested class has access to private constructor of outer class

查看:169
本文介绍了静态嵌套类可以访问外部类的私有构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

声明


静态嵌套类与其外部
类(和其他类)的实例成员交互,就像任何其他顶级类一样。
效果中,静态嵌套类在行为上是一个顶级类,为了便于打包,
已嵌套在另一个顶级类中。

那么如何解释这个静态嵌套类是否可以访问其封闭类的私有构造函数?

So how to explain this static nested class has access to private constructor of its enclosing class?

推荐答案


那么如何解释这个静态嵌套类是否可以访问其封闭类的私有构造函数?

So how to explain this static nested class has access to private constructor of its enclosing class?

因为任何 private 成员(字段,构造函数或方法)的范围和可访问性是其声明类的完整主体,包括任何嵌套类。

Because the scope and accessibility of any private member (field, constructor or method) is the complete body of its declaring class, including any nested classes.

来自 Java语言规范部分6.6.1


如果成员或构造函数是声明 private ,如果是,则允许访问d仅当它出现在包含成员或构造函数声明的顶级类(第7.6节)的主体内时。

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.

这篇关于静态嵌套类可以访问外部类的私有构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆