公共类CommonUtil中不应该有公开的构造函数

来源:互联网 发布:网络直播吃饭 编辑:程序博客网 时间:2024/06/05 00:48

Sonar静态代码检查发现下面缺陷:

Utility classes should not have a public constructor

Utility classes, which are a collection of static members, are not meant to be instantiated. Even abstract utility classes, which can be extended, should not have public constructors.
Java adds an implicit public constructor to every class which does not define at least one explicitly. Hence, at least one non-public constructor should be defined.

以后凡是公共的类都需要在里面定义该类的private的构造函数,譬如CommonUtil方法中要定义一个
private CommonUitl(){

}

0 0
原创粉丝点击