Which one is better? With `data class` or only `cl...
# android
a
Which one is better? With
data class
or only
class
? I can only see the flexibility of using
copy()
fun when its data class. Any others pros/cons?
Copy code
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
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
Larger binary size
a
Larger binary size
Cons for data class?
d
Yeah. Although it's nothing a dead code eliminator can't fix.
👍 1
a
So basically if I don't need to use `copy()`then I can go with just
class
s
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
👍 1