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))
}
The compiler objects to CS("hello") == "hello"
as: Operator '==' cannot be applied to 'CS' and 'String'. It has no problems with CS("hello") == "hello" as Any
or CS("hello").equals("hello")
which both work.
我做错了什么?