且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

内部类中私有变量的范围?

更新时间:2023-02-15 20:18:57

作用域在 Node{} 之间,但是它RedBlackTrees 下的任何代码都可以访问,前提是您提供明确的路径.

The scope is between the { and } of Node however it is accessible to any code under RedBlackTrees provided you give an explicit path.

顺便说一句,当您以这种方式访问​​私有成员时,javac 编译器必须添加访问器方法,这些方法不会减慢代码的速度,但会产生令人困惑的堆栈跟踪.为简单起见,我会让成员打包本地".

BTW When you access private members this way, the javac compiler has to add accessor methods which don't slow down the code that much but can give confusing stack traces. For simplicity I would make the members "package local".