What is the reason that it’s not possible to provi...
# announcements
m
What is the reason that it’s not possible to provide interface function default implementations for
toString()
and alike? That would be super helpful 🙂
p
I would guess because there's already an implementation on Any, so it wouldn't be a default implementation as one already exists on all objects?
m
True, but the Kotlin compiler could decide to overwrite the implementation of
Any
if that’s supposed to be a feature.
n
might also be because it's not uncommon for classes to implement multiple interfaces, and the other Any methods (equals, hashcode) usually rely on comparing private state -- actually I'd expect toString to also. dunno why it's actually prohibited, though
m
All functions have the multiple interface problem though - not Any functions 🙂
I’d find this feature especially useful for inline classes. You cannot use inheritance here and there isn’t much private state.
n
you couldn't name it toString but you could add an extension method that does what you want
m
Won’t work with string interpolation unfortunately.