Created
June 19, 2017 12:54
-
-
Save ezura/80a7bc416fec84d2f82b969ed80b86b3 to your computer and use it in GitHub Desktop.
Kotlin の Set の要素の比較、Element に制約をつけてるようにも見えないし、どうしてるんだろうと思ったら、Any に `fun equals(other: Any?): Boolean` いるからどの型でも等しいか検査可能なのね(。 ・ω・))
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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