https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
r

Ruckus

05/08/2019, 1:30 PM
(MPP newbie here, so if there's a resource I'm missing that answers my questions, please let me know) Is there no way to have a default method implementation in an expect class?
Copy code
expect class Grade : Comparable<Grade> {
    val rough: Int
    val fine: Int

    // Apparently I can't implement this here
    override fun compareTo(other: Grade) {
        var result = rough.compareTo(other.rough)
        if (result == 0) result = fine.compareTo(other.fine)
        return result
    }
}
r

russhwolf

05/08/2019, 1:34 PM
You can do
expect class Grade : GradeInterface
where
GradeInterface
has your default implementations
And specifically for
compareTo
. you could do and extension function
operater fun Grade.compareTo()
r

Ruckus

05/08/2019, 1:40 PM
Hmm, interesting. Thanks for the info.
r

russhwolf

05/08/2019, 1:44 PM
There's also https://youtrack.jetbrains.com/issue/KT-20427 around this functionality