_ClassInstance 符号?
我有一个非常基本的问题,但在文档中搜索它对我没有任何好处,可能是因为我不知道我在搜索什么。我实际上已经完成了几个程序,但从未使用过我在我一直在研究的相当多的代码示例中发现的这种表示法。
到目前为止,当我实例化一个类时,我基本上完成了以下操作:
public ClassType mclassname;
mclassname = new ClassType();
但我已经看到了这种用法:
public ClassType _mclassname;
__mclassname = new VortexView();
我找不到 2 中差异的文档,但我认为它有一些东西与使对象的多个实例变得不可能有关?
如果你知道我应该寻找什么来自己解决这个问题,那就足够了。 我只是在实例化类的文档中找不到它。
I have an incredibly basic question, but searching for it in the docs has done me no good, probably because I don't know what i'm searching for. I've actually completed several programs but never used this notation i'm finding in quite a few code examples I've been researching.
Up until now, when I've instantiated a class I've basically done the following:
public ClassType mclassname;
mclassname = new ClassType();
But I've seen this used:
public ClassType _mclassname;
__mclassname = new VortexView();
I can't find the documentation for the difference in the 2, but I'm thinking that it has something to do with making multiple instances of the object impossible?
If you know what I should look for to figure this out myself, that would be sufficient.
I just can't find it in the documents for instantiating classes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嵌套类可以声明为private
,这意味着它们只能用作封闭类内的类型。用下划线作为类成员名称的前缀没有语法意义。这是来自 C++(以及 Python,专门用于标记私有成员)的约定,在 Java 中通常不使用,但在更熟悉 C++ 或 Python 的程序员中并不罕见。
Nested classes can be declaredprivate
whcih means they can only be used as a type inside the enclosing class.Prefixing the names of class members with underscores has no syntactic meaning. It is a convention from C++ (and Python where it's specifically used to mark private members) that is not generally used in Java, but not uncommon among programmers who are more familiar with C++ or Python.