Join Slack
Powered by
Style question: When overriding a nullable val pro...
# announcements
m
Mark
03/09/2020, 10:14 AM
Style question: When overriding a nullable val property with a null, do you prefer
override val myVal = null
or
override val myVal get() = null
1️⃣ 7
2️⃣ 7
s
sindrenm
03/09/2020, 10:16 AM
I don't see any reason why we'd need to call a function that returns
null
every time, so the first one.
👍 2
d
diesieben07
03/09/2020, 10:22 AM
If the val is overridden again in a subclass you now have two fields, one of which is unused.
s
spand
03/09/2020, 10:22 AM
You call a function in both cases. I guess the difference is having a local variable for storing the null or not which seems a bit pointless
☝️ 1
s
sindrenm
03/09/2020, 10:22 AM
Yeah, I guess that's true.
3
Views
Open in Slack
Previous
Next