is there a better way to have each subclass call t...
# announcements
r
is there a better way to have each subclass call the superclasses toString method without having
Copy code
override fun toString(): String {
    return super.toString()
}
in each of the subclasses?
d
I am guessing your subclass is a
data class
?
r
You're right, does that make a difference?
s
You can call
super.toString()
or
super.someMethod
from any other method…. not sure what you are trying to accomplish
r
I see what @diesieben07 means, data classes automatically implement a toString
so I would have to override it
d
Correct. If you don't want the autogenerated toString, you need to provide your own.
Even if it just calls super
s
Ah…. yep, you can’t call
super.super.toString()
or something similar, if that is what you are trying to accomplish for your data classes.
s
You could maybe write a extension function and name ist superclassnameToString
r
@streetsofboston super.toString() works though, since my data classes extend an abstract class
s
you shouldn't really be using
data class
if you don't want the autogenerated methods though