是否应该使用大写命名来声明Java常量变量? [英] Should I use upper-case naming to declare java constant variables?
问题描述
我的问题:常量Java变量(在方法内)的名称应大写吗?
My question: Should names of constant Java variables (within methods) be upper-case?
我一直给人以
a)如果变量永远不会更改,则应将其声明为final(以显示/强制其不会更改)b)应该以大写字母命名
a) if a variable is never going to change, it should be declared final (to show/enforce that it won't change) b) it should be named in upper-case
但是,我在日食中注意到,将变量(在方法内)更改为最终/常量,随后将其重构/重命名为以下内容:
However, I've noticed in eclipse, when changing a variable (within a method) to be final/constant, and subsequently refactoring/renaming it to something like below:
final int NODE_COUNT = 3;
我收到以下警告:
不建议使用此名称.根据约定,局部变量的名称应以小写字母开头.
This name is discouraged. According to convention, names of local variables should start with a lowercase letter.
这让我想知道大写规则在这种情况下是否不适用(即方法中的最终变量).
Which makes me wonder if the upper-case rule doesn't apply in this instance (i.e. final variable within a method).
推荐答案
在方法中,您没有常量,只有局部变量,可以是 final
.因此,从小写字母开始使用普通的camelCase非常适合在那里.
Within methods you don't have constants, you just have local variables, that can be final
. So using normal camelCase starting with lowercase is perfectly suiting there.
这篇关于是否应该使用大写命名来声明Java常量变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!