[K/N] Do not override equals/hashCode for AbstractMutableMap.values collection
This commit is contained in:
committed by
Space Team
parent
6015e12db8
commit
e802ee05a7
@@ -97,15 +97,6 @@ public actual abstract class AbstractMutableMap<K, V> protected actual construct
|
|||||||
}
|
}
|
||||||
|
|
||||||
override val size: Int get() = this@AbstractMutableMap.size
|
override val size: Int get() = this@AbstractMutableMap.size
|
||||||
|
|
||||||
// TODO: should we implement them this way? Currently it's unspecified in JVM
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (other !is Collection<*>) return false
|
|
||||||
return AbstractList.orderedEquals(this, other)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int = AbstractList.orderedHashCode(this)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return _values!!
|
return _values!!
|
||||||
|
|||||||
@@ -74,6 +74,9 @@ class AbstractCollectionsTest {
|
|||||||
compare(map.toMap(), map) {
|
compare(map.toMap(), map) {
|
||||||
mapBehavior()
|
mapBehavior()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// values collection does not provide equals implementation
|
||||||
|
assertNotEquals(map.values, ReadOnlyMap().values)
|
||||||
}
|
}
|
||||||
|
|
||||||
class MutColl(val storage: MutableCollection<String> = mutableListOf()) : AbstractMutableCollection<String>() {
|
class MutColl(val storage: MutableCollection<String> = mutableListOf()) : AbstractMutableCollection<String>() {
|
||||||
@@ -165,5 +168,8 @@ class AbstractCollectionsTest {
|
|||||||
compare(map.storage, map) {
|
compare(map.storage, map) {
|
||||||
mapBehavior()
|
mapBehavior()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// values collection does not provide equals implementation
|
||||||
|
assertNotEquals(map.values, MutMap(map).values)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user