Skip to content

Instantly share code, notes, and snippets.

@ezura
Created June 19, 2017 12:54
Show Gist options
  • Select an option

  • Save ezura/80a7bc416fec84d2f82b969ed80b86b3 to your computer and use it in GitHub Desktop.

Select an option

Save ezura/80a7bc416fec84d2f82b969ed80b86b3 to your computer and use it in GitHub Desktop.
Kotlin の Set の要素の比較、Element に制約をつけてるようにも見えないし、どうしてるんだろうと思ったら、Any に `fun equals(other: Any?): Boolean` いるからどの型でも等しいか検査可能なのね(。 ・ω・))
class A(val v1: Int) {
init {
require(v1 < 0, {"aaaaaa"})
}
override fun hashCode(): Int {
return v1
}
override fun equals(other: Any?): Boolean {
return true
}
// override fun toString(): String {
// val value: Any = this + 1
// val a = 1 + this
//
//// val i: Double = 1.toDouble()
//// val list = listOf<Int>()
//// val set = setOf<A>(A(-1), A(-1))
//// """
////qqq
////QQQ
////QQQ
////""".trimMargin()
//
// val array = arrayOfNulls<Int>(5)
// return a.toString
// }
operator fun plus(that: Int): Int {
return that + 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment