Java Checkstyle 中的“变量访问定义顺序错误”是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6391540/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 05:33:35  来源:igfitidea点击:

What does "variable access definition in wrong order" mean in Checkstyle?

javacheckstyle

提问by Manoj

I run checkstyle on my Javacode and get this error:

我在Java代码上运行 checkstyle并收到此错误:

variable access definition in wrong order

顺序错误的变量访问定义

Can somebody tell me what that means?

有人能告诉我这是什么意思吗?

回答by Michael Lowman

I'm guessing you have something like static public int. Normally, that would be written as public static int.

我猜你有类似的东西static public int。通常,这将被写为public static int.

回答by Sai

Could it be that you have declaration order configured in CheckStyle? Take a look at http://checkstyle.sourceforge.net/config_coding.html#DeclarationOrder

会不会是你在CheckStyle中配置了声明顺序?看看 http://checkstyle.sourceforge.net/config_coding.html#DeclarationOrder

In that link, you will notice that it says ... *According to Code Conventions for the Java Programming Language , the parts of a class or interface declaration should appear in the following order:

在该链接中,您会注意到它说 ... *根据 Java 编程语言的代码约定,类或接口声明的部分应按以下顺序出现:

Class (static) variables.
First the public class variables,
then the protected,
then package level (no access modifier), and
then the private.

类(静态)变量。
首先是公共类变量,
然后是受保护的,
然后是包级别的(无访问修饰符),
然后是私有的。

Instance variables.
First the public class variables,
then the protected,
then package level (no access modifier), and
then the private Constructors Methods*

实例变量。
首先是公共类变量,
然后是受保护的,
然后是包级别(无访问修饰符),
然后是私有的构造函数方法*