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?
y
07/26/2023, 3:39 PM
wait, is this a limitation of format strings?
s
Sam
07/26/2023, 3:40 PM
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.
Sam
07/26/2023, 3:41 PM
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
y
07/26/2023, 3:42 PM
I see. thank you 👍
y
07/26/2023, 3:43 PM
(and yes, IntelliJ does warn about it being redundant in my case)