gpt4 book ai didi

java - 有关记录器的 Pmd 错误

转载 作者:行者123 更新时间:2023-12-02 05:28:29 25 4
gpt4 key购买 nike

我的代码中有这一行:

private transient final Logger logger = LoggerFactory.getLogger(getClass());

我构建了我的项目,pmd 检查告诉我:

The Logger variable declaration does not contain the static and final modifiers.

我可以做什么来解决这个问题?我尝试添加 static 修饰符,但出现以下错误:

Cannot make a static reference to the non-static method getClass() from the type Object

最佳答案

如果您在 main 中使用它,请将其静态化

我会使用这样的记录器

private static final Logger LOG = Logger.getLogger(Main.class.getSimpleName());

关于java - 有关记录器的 Pmd 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25774099/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com