Hide Utility Class Constructor : Utility classes should not have a public or default constructor

前端 未结 10 1257
伪装坚强ぢ
伪装坚强ぢ 2021-01-30 03:51

I am getting this warning on Sonar.I want solution to remove this warning on sonar. My class is like this :

public class FilePathHelper {
    private static Stri         


        
10条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-30 04:08

    I don't know Sonar, but I suspect it's looking for a private constructor:

    private FilePathHelper() {
        // No-op; won't be called
    }
    

    Otherwise the Java compiler will provide a public parameterless constructor, which you really don't want.

    (You should also make the class final, although other classes wouldn't be able to extend it anyway due to it only having a private constructor.)

提交回复
热议问题