泛型方法指定返回值类型
程序员文章站
2022-07-15 14:18:23
...
public static <T> T getCache(String namespace, Class<T> clazz) throws IOException, ClassNotFoundException{
CacheItem<Serializable> item = cacheMap.get(namespace);
T t = null;
if(item == null){
File file = new File("c:/cache/" + namespace + ".txt");
if(file.exists()){
FileInputStream fileInputStream = new FileInputStream(file);
ObjectInputStream inputStream = new ObjectInputStream(fileInputStream);
t = (T) inputStream.readObject();
}
}
return t;
}
CacheItem<Serializable> item = cacheMap.get(namespace);
T t = null;
if(item == null){
File file = new File("c:/cache/" + namespace + ".txt");
if(file.exists()){
FileInputStream fileInputStream = new FileInputStream(file);
ObjectInputStream inputStream = new ObjectInputStream(fileInputStream);
t = (T) inputStream.readObject();
}
}
return t;
}
上一篇: 思维与态度 大数据数据分析数据
下一篇: java异常分类