日期:2014-05-17  浏览次数:20758 次

单例里面如何设计一个map对象!真心求代码!
如题!求代码!求详细注释!

------解决方案--------------------
Java code

package test;

import java.util.HashMap;
import java.util.Map;

public class SingleTon {

    private Map<Object,Object> map;
    
    private static SingleTon singleTon;
    
    private SingleTon(){
        map = new HashMap<Object,Object>();
    }
    
    public static SingleTon getSingleTon(){
        if(singleTon == null){
            singleTon = new SingleTon();
        }
        return singleTon;
    }
    
    public void put(Object key, Object value){
        map.put(key, value);
    }
    
    public Object get(Object key){
        return map.get(key);
    }
}