import java.util.HashMap;
import java.util.Map;
public class test001<T, K, V> {
private T data;
private Map<K,V> map;
public Map<K, V> getMap() {
return map;
}
public void setMap(Map<K, V> map) {
this.map = map;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
public test001(T data) {
super();
this.data = data;
}
public test001(){
}
public test001(T data, Map<K, V> map) {
super();
this.data = data;
this.map = map;
}
public static void main(String[] args){
test001<String,String,String> test001 = new test001<String,String,String>();
test001<String,String,String> test002 = new test001<String,String,String>("dfds",new HashMap<String,String>());
Map<String, String> map = new HashMap<String,String>();
map.put("s1", "hello1");
map.put("s2", "hello2");
test001.setMap(map);
test001.setData("s3");
System.out.println(test001.getData());
System.out.println(test001.getMap().get("s1"));
System.out.println(test001.getMap().get("s2"));
}
}
当在项目中遇到参数类型不确定时可以使用泛型解决,这样减少代码量,提高可读性,避免程序出现运行时错误