y
07/26/2023, 3:37 PMsealed 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?y
07/26/2023, 3:39 PMSam
07/26/2023, 3:40 PMtoString
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 PMdata 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
07/26/2023, 3:42 PMy
07/26/2023, 3:43 PMYoussef Shoaib [MOD]
07/26/2023, 10:47 PMfinal
to change that behaviour somehow