robin
03/06/2017, 8:03 PMval any = object {
override fun equals(other: Any?) = true
}
but only works when doing any == "Test"
, not the other way around: "Test" == any
. Is there any way to make the latter work?mfulton26
03/06/2017, 8:17 PMrobin
03/06/2017, 8:19 PMwhen(a to b) {
0 to 0 -> ...
0 to any -> ...
any to 0 -> ...
}
mfulton26
03/06/2017, 8:20 PMfun main(args: Array<String>) {
println("Test".compareTo(Anything))
println(Anything.compareTo("Test"))
}
object Anything : Comparable<Any?> {
override fun compareTo(other: Any?) = 0
}
fun Any?.compareTo(anything: Anything) = 0
robin
03/06/2017, 8:21 PMwhen
statement uses the Comparable
interface, does it?mfulton26
03/06/2017, 9:25 PMif (a == 0 && b == 0) {
} else if (a == 0) {
} else if (b == 0) {
}
when
to:
when {
a == 0 && b == 0 -> ...
a == 0 -> ...
b == 0 -> ...
}
when (0) {
a or b -> ...
a -> ...
b -> ...
}
robin
03/06/2017, 10:06 PM