UserKey类是单例设计模式吗?
来源:2-7 集成redis下

慕雪8012440
2019-01-05
public class UserKey extends BasePrefix{
private UserKey(String prefix) {
super(prefix);
}
public static UserKey getById = new UserKey("id");
public static UserKey getByName = new UserKey("name");
}
请问老师,UserKey类的构造函数私有化了,是否说明就是单例设计模式?每次调用UserKey.getById或UserKey.getByName的时候,是否返回的都是同一个对象呢?
写回答
1回答
-
若鱼1919
2019-01-07
UserKey不是单例,因为getById 和 getByName 已经有2个实例了。但是每次调用,确实返回的是同一个对象,因为static在jvm中只有一份
00
相似问题