Chris Fillmore
10/04/2021, 2:19 PMSet
compared via equals()
?Grégory Lureau
10/04/2021, 2:22 PMJoffrey
10/04/2021, 3:38 PMSet
interface defines equality using equals()
, but the Kotlin definition is lousy here (honestly most of Kotlin's stdlib KDoc is really less precise than the Java counterpart, potentially because it could vary across platforms).
So technically in Kotlin it depends on the `Set`'s implementation, but it's a pretty safe bet to say that equality should be based on equals()
in most implementations (at least on the JVM). The most common one (HashSet
) uses hashCode()
and then equals()
to break ties as @Grégory Lureau said.ephemient
10/04/2021, 4:10 PMChris Fillmore
10/04/2021, 4:12 PMephemient
10/04/2021, 7:23 PMequals
, because it uses object identity instead. also SortedSet/SortedMap can be inconsistent with equals depending on the implementation of Comparable.compareTo or Comparator.compare. but the point stands that sets and map keys are generally expected to compare by equalsJoffrey
10/04/2021, 7:27 PMIdentityHashMap
, thanks!