1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
package
test;
class
Singleton
{
private
static
Singleton instance;
private
Singleton(){}
public
static
Singleton getInstance()
{
if
(instance==
null
)
{
instance=
new
Singleton();
}
return
instance;
}
}
public
class
JTest
{
public
static
void
main(String[] args)
{
Singleton s1=Singleton.getInstance();
Singleton s2=Singleton.getInstance();
System.out.println(s1==s2);
}
}
|
单例模式
最新推荐文章于 2025-05-23 19:33:43 发布