开发者

Map vs Map<K,V>

开发者 https://www.devze.com 2023-02-16 22:50 出处:网络
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 appro

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

精彩评论

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

关注公众号