https://kotlinlang.org logo
#android
Title
# android
l

lawlorslaw

07/04/2019, 3:37 PM
what is the best way to override a getter in data class? i came across this post https://code.luasoftware.com/tutorials/kotlin/override-getter-for-data-class/
m

mikaelquick

07/04/2019, 4:42 PM
First of all do I think this code is hard to read so I would rethink my options. But you know more since you have the bigger picture. If you really really need to have the code that way, put the logic into a function that handle the logic in get
Sorry for the bad English
a

Alowaniak

07/04/2019, 6:25 PM
I'm not sure of a good usecase to override the getter? In the given example I would think a factory function would make more sense so you can't create one with empty id
r

rkeazor

07/04/2019, 9:03 PM
lol overriding a getter inside data class doesn't seem to cool lol. perhaps you need a open class or a abstract class instead
8 Views