class Person {
public Person getInstance()
- {
- if(person==null)
- {
- synchronized(this)
- {
- if(person==null)
- person =new Person();
- }
- }
- return person ;
- }
单例模式就是在内存中想只能存在一个对象,而不允许再实例化其他的对象
class Person {
public Person getInstance()
单例模式就是在内存中想只能存在一个对象,而不允许再实例化其他的对象