单例里面怎么设计一个map对象真心求代码
发布网友
发布时间:2023-09-22 12:27
我来回答
共1个回答
热心网友
时间:2024-12-04 03:42
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);
}
}