sealed class Errors(open val errorCode: String) {
data class SomeError(
override val errorCode: String
) : Errors(errorCode)
}
OR
sealed class Errors(open val errorCode: String) {
class SomeError(
override val errorCode: String
) : Errors(errorCode)
}
s
stantronic
05/06/2022, 11:46 AM
Some benefits of data class would include
• equality tests
• copy()
• (if the error ever had more than one property) the ability to positionally destructure.
Can’t think of any major cons
👍 2
d
Dominaezzz
05/06/2022, 12:06 PM
Larger binary size
a
Ali
05/06/2022, 12:10 PM
Larger binary size
Cons for data class?
d
Dominaezzz
05/06/2022, 12:12 PM
Yeah. Although it's nothing a dead code eliminator can't fix.
👍 1
a
Ali
05/06/2022, 12:16 PM
So basically if I don't need to use `copy()`then I can go with just
class
s
stantronic
05/07/2022, 10:50 AM
if you don’t need equality testing,
copy()
or destructuring then you can go with class. Personally i find the equality testing is often the reason i go with data classes