the comparison operators (>, < etc) can call...
# getting-started
f
the comparison operators (>, < etc) can call directly to Java's own
compareTo
methods? They don't need Kotlin's
Comparable
interface?
k
Java's
compareTo
is also from the
Comparable
interface.
But for Kotlin code the
Comparable
interface isn't actually required,
operator fun compareTo
is enough.
f
but it also works with Java's Date and its
compareTo
is not an operator fun
k
Yes, you need to implement
Comparable
or have
operator fun compareTo
.
Or you know just consider it compiler magic, it maps
java.util.Comparable
to
koltin.Comparable
which has an operator.
f
Is the last sentence actually true?
or is there an extension function somewhere
k
No it's true, there's a bunch of type mapping going on. If you have a list of
kotlin.Comparable
you can put a
Date
in it.
f
I see, thank you
d
java.util.Date
is
Comparable
...
k
Yes, so it matches the first one:
Yes, you need to implement
Comparable
or have
operator fun compareTo
.
d
I think I misread something up there. It's too early.
f
but it's Java's Comparable?
Not Kotlin?
f
thanks