Pass checkstyle to Java Hello World

So I'm a novice using checkstyle. For my simple HelloWorld Java program, I received a lot of errors that I don't understand

My code:

package <package_name>;

/**
* A simple class to compile.
*/
public class HelloWorld {

 /**
  * @param args standard main parameters
  */

    public static void main(String[] args) {
        System.out.println("hello world");
    }
}

I received an error:

Line 6: Utility classes should not have a public or default constructor
Line 10: Parameter args should be final

Why is that? Is it necessary for me to create a private constructor for my main class and make the default parameters final?

Solution

For utility classes such as the main class, it is best to create a private constructor so that the java compiler does not write the default no args constructor main()

Java always copies parameters before sending them to methods The final keyword here only means that variables cannot be reassigned inside the method (note that if you have a final object like string [] in your case, you can still change the properties of the object)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>