Java常量变量,命名约定 [英] Java constant variable, naming convention

查看:153
本文介绍了Java常量变量,命名约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java常量变量是否有任何命名约定?

通常我们使用名称中包含大写字母和下划线的变量( _ )。 br />

Is there any naming convention for java constant variable?
Normally we use variables with names containing uppercase letters and underscores(_).

例如:

public final class DeclareConstant {

    public static final String CONSTANT_STRING = "some constant";

    public static final int CONSTANT_INTEGER = 5;

}


推荐答案

是的。这就对了。它通常用于枚举

Yes. That is it. It is often used for enum as well.

唯一常见的例外是记录你可能会看到的地方

The only common exception is for logging where you might see

private static final Logger log = Logger.getLogger(getClass().getName());

但我更喜欢 LOG

我经常把它写成UPPER_CASE,但是我也为类编写了TitleCase,为变量和方法编写了camelCase。

I often write this as UPPER_CASE, but I also write TitleCase for classes and camelCase for variables and methods.

这篇关于Java常量变量,命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆