I'm trying to have typed Ids, so I created a inter...
# getting-started
u
I'm trying to have typed Ids, so I created a interface
Copy code
interface Id : Comparable<Id> {
    val value: String
    
    override fun compareTo(other: Id): Int = value.compareTo(other.value)
    fun toString(): String = value
}
but it complains
'toString' hides member of supertype 'Comparable' and needs 'override' modifier
which is nonsense, but if I remove the comparable, then it complains that im hiding
Any
is this possible?
a
It is not nonsense but Kotlin wants you to override the
toString
method, because it is already present in Comparable if I remember correctly
u
no its not
r
You can’t override
toString
in an interface. Just have to leave it to the implementations of
Id
. Or make
Id
an
open class
rather than an interface.
a
It's already implemented in Any class, which every Class extends in Kotlin
r
Copy code
open class Id(
  val value: String
) : Comparable<Id> {
  final override fun compareTo(other: Id): Int = value.compareTo(other.value)
  final override fun toString(): String = value
}
u
yea I figured its impossible, its just that the error messages are bs imo
p
u
Yea but dagger doesnt work with them yet