本帖最后由 sofeel 于 2015-2-26 15:45 编辑
- public class Testt {
- public static void main(String[] args) {
- /*
- * 用Object实现。(泛型做不了)
- * */
- }
- }
- class BaseManager{
-
- public BaseManager(){}
- public static Object getInstance(){
- return new Object();
- }
- }
- //饿汉
- class Zi1 extends BaseManager{
-
- private static Zi1 zi1=new Zi1();
- private Zi1() { }
-
- public static Zi1 getInstance(){
- return zi1;
- }
- }
- //懒汉
- class Zi2 extends BaseManager{
-
- private static Zi2 zi2;
- private Zi2() { }
-
- public static Zi2 getInstance(){
- if(zi2==null)//没考虑同步
- zi2=new Zi2();
- return zi2;
- }
- }
复制代码
|