接口作为通用参数

时间:2014-09-26 00:34:01

标签: java generics interface

对于Map本身我该怎么做

Map<Object, Object> map1 = new HashMap<Object, Object>();

但对于Map中的Map,我无法做到

Map<Object, Map<Object, Object>> map2 = new HashMap<Object, HashMap<Object, Object>>();

相反,我必须做

Map<Object, HashMap<Object, Object>> map3 = new HashMap<Object, HashMap<Object, Object>>();

这种情况并非Maps所独有,它也与Set有关,我假设所有其他接口。换句话说,我不能将接口用作泛型。为什么不呢?

0 个答案:

没有答案