Skip to content

Instantly share code, notes, and snippets.

@Bruce0203
Last active April 3, 2023 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bruce0203/f6bbd8c5df18f167d7b2998390e727aa to your computer and use it in GitHub Desktop.
Save Bruce0203/f6bbd8c5df18f167d7b2998390e727aa to your computer and use it in GitHub Desktop.
DoesHashMapWorkWithNonHashCodeEquals.kt
import java.util.UUID
var isEqualsFunctionCalled = false
data class KeyObj(val uuid: UUID = UUID.randomUUID()) {
override fun equals(other: Any?): Boolean {
isEqualsFunctionCalled = true
return super.equals(other)
}
override fun hashCode(): Int {
return uuid.hashCode()
}
}
fun main() {
val map = hashMapOf(KeyObj() to "abc")
map[KeyObj()]
println("isEqualsFunctionCalled=$isEqualsFunctionCalled")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment