I expect two identical transforms to result objects that have the same hashCode. I’d like to use this property to check whether my object has changed in a meaningful way.
Unfortunately, Guava’s TransformedCollection extends AbstractCollection which (unlike AbstractList) does not implement hashCode or equals, and TransformedCollection does no such attempt itself.
- Could we not calculate a
hashCodebased on the values as returned by the iterator’s order or some such? - Or would that still not guarantee identical
hashCodes? - Perhaps we can solve this problem for
TransformedCollectionin a way it cannot be solved forAbstractCollection?
Unfortunately, there’s no sane way for defining
Collection.hashCode. A collection can be aSetor aList(or something else) and the two definehashCodein an incompatible way.Moreover, for the same reason there’s no sane definition for
transformedCollection1.equals(transformedCollection2). It could either ignore the order, or not (Set or List semantics). Even worse, the returnedCollectionis just a view, and suchequalswould be terrible inefficient.I’d suggest to use something like
ImmutableList.copyOf(transformedCollection)and work with it.