I've got a `sealed class` which overrides `toStrin...
# getting-started
y
I've got a
sealed class
which overrides
toString()
, and has
data class
subclasses in the subclasses, I have functions which have format strings with
$this
in them. surprisingly, the
toString()
implementation used is the default, non-override Kotlin implementation if I add
override fun toString() = super.toString()
to each subclass, I get the expected
toString()
implementation, but IntelliJ marks it as a redundant overriding method is IntelliJ just wrong, or is there a better way to do this?
wait, is this a limitation of format strings?
s
If IntelliJ is marking a
toString
override in a data class as redundant, then yes, IntelliJ is wrong. It doesn’t do that for me, though. It warns me about the redundant override in a normal class, but if I make it a
data class
the warning goes away.
A
data class
automatically overrides
toString
, which is why you’re seeing the “default” implementation being used. Providing your own override is basically a way to replace the default override.
y
I see. thank you 👍
(and yes, IntelliJ does warn about it being redundant in my case)
y
IIRC you need to mark it as
final
to change that behaviour somehow