https://kotlinlang.org logo
#getting-started
Title
# getting-started
p

Patrick Ramsey

08/27/2021, 4:41 AM
Hmm… not sure where to post this since #general is now #announcements But does anyone know if there’s a way for a data class to inherit its toString() implementation from another class? (ie, is there a way to not get the automatically generated data class toString() implementation)
Blah, looks like one (unintuitive) answer is to explicitly add,
Copy code
override fun toString() = super.toString()
to the data class(es).
e

ephemient

08/27/2021, 6:40 AM
yeah, there isn't a straightforward way of turning off particular data class features. no-copy plugin could be modified to no-toString if you wanted though
y

Youssef Shoaib [MOD]

08/27/2021, 8:24 PM
Also, if you control its superclass, you can make its
toString
method final, and so the data modifier won't generate its own