分析Java代码时出现checkstyle错误 [英] checkstyle error when analyzing java code

查看:93
本文介绍了分析Java代码时出现checkstyle错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Spring Boot应用程序中启动Checkstyle分析时出现此错误:

i got this error when launching checkstyle analysis in a spring boot app :

SpringBootBackend.java:7:1  error: Les classes utilitaires ne doivent pas avoir de constructeur par défaut ou public.

代码:

  public class SpringBootBackend{

public static void main(String[] args) {

    SpringApplication.run(SpringBootBackend.class, args);
   }
}

有什么帮助吗?

推荐答案

仅包含静态方法的类在此检查中被视为实用程序类。这样的类应该只有私有的构造函数,这样才不会意外实例化它们。它们也应该是 final

Classes which contain only static methods are considered "utility classes" by this check. Such classes should have only private constructors, so that they are not accidentally instantiated. They should also be final.

因此,您可以添加如下构造函数:

So, you can add a constructor like this:

private SpringBootBackend() {}

并可能声明类 final ,错误应该消失了。

and possibly declare the class final, and the error should be gone.

这篇关于分析Java代码时出现checkstyle错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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