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 Any或CS("hello").equals("hello")两者都有效。
我究竟做错了什么?
kotlin ×1