Hi there,
Big fan of fastutil! Thanks for all the work you put into it, Sebastiano, and other volunteers.
Today I noticed a frustrating gap between the jdk collections and fastutil collections regarding the "unmodifiable" methods.
In the jdk methods, you can take a Collection<? extends T> and get back a Collection<T> -- with a super type for the parameter -- by wrapping it in Collections.unmodifiableCollection [
link]:
public static <T> Collection<T> unmodifiableCollection(Collection<? extends T> c)
Likewise for maps, with similar upcasting on the key types as well (except in the case of SortedMaps) [
link]:
public static <K,V> Map<K,V> unmodifiableMap(Map<? extends K,? extends V> m)
This is generally safe to do because the resulting unmodifiable thing cannot be mutated by, say, adding a String into a Collection<Animal> simply by wrapping the latter in unmodifiableCollection to get a Collection<Object> instead.
But in the case of fastutil, the corresponding "unmodifiable" methods don't support any such changing of the generic types. For example, in Int2ObjectSortedMaps [
link]:
public static <V> Int2ObjectSortedMap<V> unmodifiable(Int2ObjectSortedMap<V> m)
Is there some limitation to the implementation that would preclude this relaxing of the types for unmodifiable collections? Or is it just not something that's been addressed before?
Best,
Scott