静态修改器方法的 Java 命名约定
对于Java中的静态方法,参数不能与全局静态变量同名。参数命名有约定吗? ……只是好奇而已。
私有静态易失性 int metBetYetPetLetJet = 8675309;
公共静态无效setMetBetYetPetLetJet(int metBetYetPetLetJet0){
metBetYetPetLetJet = metBetYetPetLetJet0;
}
For static methods in Java, the parameter cannot have the same name as a global static variable. Is there a convention for naming the parameter? ...just a curiosity.
private static volatile int metBetYetPetLetJet = 8675309;
public static void setMetBetYetPetLetJet (int metBetYetPetLetJet0) { metBetYetPetLetJet = metBetYetPetLetJet0; }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
参数绝对可以具有相同的名称:
或者,我经常使用
value
作为setter的参数名称。不过,这可能是 C# 的影响:) 另一种选择是newValue
。The parameter absolutely can have the same name:
Alternatively, I often just use
value
as the parameter name for a setter. That may be the influence of C# though :) Another option isnewValue
.您可以给出相同的名称,并且规则应用与成员变量名称相同。
这里:您必须使用类名引用变量,而不是
this
。You can give the same name and the rule applies the same as for the member variable's name.
Here: instead of
this
you have to refer the variable with the class name.