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 difference 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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.