gpt4 book ai didi

sonarqube - 如何使代码符合: Move this variable to comply with Java Code Conventions

转载 作者:行者123 更新时间:2023-12-04 08:57:57 27 4
gpt4 key购买 nike

我有以下类(class):

public final class AppConst {
private AppConst() {}

public static final String READ_ERROR = "READ";
public static final String PROCESS_ERROR = "PROCESS";
public static final String WRITE_ERROR = "WRITE";
}

SonarQube 用变量在所有三行上标记错误:

Move this variable to comply with Java Code Conventions.

如何让代码兼容SonarQube?

我正在使用 SonarLint for Eclipse v2.6.0。

最佳答案

问题是由 RSPEC-1213 The members of an interface or class declaration should appear in a pre-defined order 发现的规则。描述说:

According to the Java Code Conventions as defined by Oracle, the members of a class or interface declaration should appear in the following order in the source files:

  • Class and instance variables
  • Constructors
  • Methods

您的代码在变量之前包含一个构造函数。有效代码:

public final class AppConst {   
public static final String READ_ERROR = "READ";
public static final String PROCESS_ERROR = "PROCESS";
public static final String WRITE_ERROR = "WRITE";

private AppConst() {}
}

关于sonarqube - 如何使代码符合: Move this variable to comply with Java Code Conventions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63711177/

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