小编epo*_*che的帖子

在 Kotlin 中覆盖 equals

CS实施kotlin.CharSequence. 它的精髓在这里:

class CS  (val sequence: CharSequence = "") : CharSequence {
... override get/length in interface CharSequence 
    override fun equals(other: Any?): Boolean =
            (this === other) || ((other is String) && this.sequence.equals(other))
}
Run Code Online (Sandbox Code Playgroud)

编译器对象CS("hello") == "hello"为:运算符 '==' 不能应用于 'CS' 和 'String'。它没有问题CS("hello") == "hello" as AnyCS("hello").equals("hello")两者都有效。

我究竟做错了什么?

kotlin

18
推荐指数
1
解决办法
1万
查看次数

标签 统计

kotlin ×1