应该是“静态最终记录器”吗?在UPPER-CASE中宣布? [英] Should a "static final Logger" be declared in UPPER-CASE?

查看:101
本文介绍了应该是“静态最终记录器”吗?在UPPER-CASE中宣布?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,静态最终变量是常量,惯例是它们应该是大写的。但是,我已经看到大多数人声称小写的记录器在 PMD 中出现违规行为。

In Java, static final variables are constants and the convention is that they should be in upper-case. However, I have seen that most people declare loggers in lower-case which comes up as a violation in PMD.

例如:

private static final Logger logger = Logger.getLogger(MyClass.class);

只需搜索 google SO 为静态最终记录器,你会看到这个为你自己。

Just search googleor SO for "static final logger" and you will see this for yourself.

我们应该使用LOGGER吗?

Should we be using LOGGER instead?

推荐答案

记录器引用不是常量,而是最终引用,不应该是大写的。常量VALUE应为大写。

The logger reference is not a constant, but a final reference, and should NOT be in uppercase. A constant VALUE should be in uppercase.

private static final Logger logger = Logger.getLogger(MyClass.class);

private static final double MY_CONSTANT = 0.0;

这篇关于应该是“静态最终记录器”吗?在UPPER-CASE中宣布?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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