开发者

Map vs Map<K,V>

I'd like to find out why UnmodifiableMap.decorate(Map map) from Apache Commons operates on Map and returns Map instead of Map<K,V>. What's the di开发者_运维技巧fference between these two approaches?


I believe the Apache Commons collections predate generics, and haven't been updated for them.

You may wish to look at this unofficial version which is a port of Apache Commons Collections to generics, or at Guava for an alternative library with support for other collections. (There are others, of course.)


I think it is because of some sort of backward compatibility. The Map<K,V> can be used just in Java 5 and above.


Jon is probably right.

You may be able to cast to Map when it's retruned.

Map<K,V> myMap = (Map<K,V>)UnmodifiableMap.decorate(Map map);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜