In Kotlin, extension functions cannot override member functions; moreover, they are statically allowed . This means that if you write the fun Something.toString() = ... extension function fun Something.toString() = ... , s.toString() will not be allowed to it, because the member always wins .
But in your case, nothing prevents you from overriding toString inside the Something body, because data classes can have bodies similar to regular classes:
data class Something( val a: String, val b: Any, val c: String ) { override fun toString(): String = a + b + c }
source share