mirror of https://github.com/Black-Gold/Learn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
375 B
21 lines
375 B
public class Jb24_Single
|
|
{
|
|
//单例设计模式
|
|
//解决问题:确保一个类在内存中的对象唯一性
|
|
public static void main(String[] args)
|
|
{
|
|
//Single sDemo = Single.getInstance();
|
|
Single sDemo = Single.s; //等同于Single sDemo = Single.getInstance();
|
|
}
|
|
}
|
|
|
|
class Single
|
|
{
|
|
static Single s = new single();
|
|
private Single(){};
|
|
public static Single getInstance()
|
|
{
|
|
return s;
|
|
}
|
|
}
|