首页
IT
登录
6mi
u
盘
搜
搜 索
IT
通过私有构造器,使工具类不可实例化,也不可继承
通过私有构造器,使工具类不可实例化,也不可继承
xiaoxiao
2021-03-25
52
//Noninstantiable utility class
public
class
UtilityClass
{
//Suppress default constructor for noninstantiability
private
UtilityClass
(){
throw
new
AssertionError(); }
//other method
}
私有化的构造器,使子类不能实例化,因为没有可访问的构造方法,也不能实例化。
转载请注明原文地址: https://ju.6miu.com/read-32653.html
技术
最新回复
(
0
)