toString returns a textual representation of an object. Kotlin classes provide it by default, but the default output, such as Customer@5e9f23b4, is mainly useful for identifying the class and is poor for debugging or logging. Override it to produce meaningful field values. section 4.3.1
Readable customer output
class Customer(val name: String, val postalCode: Int) { override fun toString() = "Customer(name=$name, postalCode=$postalCode)" } fun main() { val customer = Customer("Alice", 342562) println(customer) // Customer(name=Alice, postalCode=342562) } The override supplies a compact, informative representation; println uses it when displaying the object.
