Skip to content

Instantly share code, notes, and snippets.

@gunkim
Created April 5, 2022 09:04
Show Gist options
  • Save gunkim/90504dd8ecb92dc3eff86e715f46690f to your computer and use it in GitHub Desktop.
Save gunkim/90504dd8ecb92dc3eff86e715f46690f to your computer and use it in GitHub Desktop.
fun hashCodeOf(vararg values: Any?): Int =
values.fold(0) { acc, value ->
(acc * 31) + value.hashCode()
}
class Category(
val id: Long? = null,
val name: String,
val createdAt: LocalDateTime? = null,
val updatedAt: LocalDateTime? = null
) {
override fun equals(other: Any?): Boolean = this === other ||
other is Category &&
id == other.id &&
name == other.name &&
createdAt == other.createdAt &&
updatedAt == other.updatedAt
override fun hashCode(): Int = hashCodeOf(id, name, createdAt, updatedAt)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment