I have created a data class
data class Something (
val a : String,
val b : Object,
val c : String
)
as later in my program, I nee
In Kotlin, extension functions cannot override member functions, moreover, they are resolved statically. It implies that if you write an extension function fun Something.toString() = ...
, s.toString()
won't be resolved to it, because member always wins.
But in your case, nothing stops you from overriding toString
inside Something
class body, because data
classes can have bodies just like regular classes:
data class Something(
val a: String,
val b: Any,
val c: String
) {
override fun toString(): String = a + b + c
}