java中对象的命名约定 [英] Naming convention for objects in java
问题描述
我在2年前开始使用java编程。当时我们项目中的老年人建议我将obj附加到正在创建的对象的名称上。
I had started programming in java 2 years back. Seniors in our project at that time had advised me to append 'obj' to the name of the object which is being created.
Ex:
Car objCar = new Car("Ferrari");
这里 objCar
正在谈论的内容。但Stack溢出的许多人反对它,现在我发现这不应该是对象命名的方式。在使用集合时很清楚使用命名约定但是在创建常规类的对象时会感到困惑。
Here objCar
is what am talking about. But many at Stack overflow had opposed it and now I find that this shouldn't be the way naming of an object should be done. Am clear with naming conventions when collections are used but am confused when objects of general classes are created.
任何人都可以对它有所了解吗?
Can anyone shed some light on it ?
推荐答案
只需将其称为 car
。 Sun / Oracle不使用匈牙利表示法。
Just call it car
. Hungarian notation is not used by Sun/Oracle.
以描述其使用的方式命名变量。但是您不需要在变量名称中指明类型。您已在变量声明中指定了类型。如果你将鼠标放在它们上面,IDE会显示变量的类型,以便随时可以获得信息。
Name your variables in a manner which describes their use. But you don't need to indicate the type in the variable name. You already specified the type in the variable declaration. IDEs will show you the type of the variable if you mouse-over them so that information is always readily available.
你应该使用 lowercaseStartingCamelCase
表示变量名和方法名, UppercaseStartingCamelCase
表示类名。
You should use lowercaseStartingCamelCase
for variable names and method names, and UppercaseStartingCamelCase
for class names.
如果你想了解Sun / Oracle如何做事,您可以阅读他们的代码约定Java编程语言。
If you want to read how Sun/Oracle do things, you can read their Code Conventions for the Java Programming Language.
这篇关于java中对象的命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!