Weird question: are there any reason why we can’t ...
# announcements
l
Weird question: are there any reason why we can’t do (besides current compiler)
val optional: String? = if (someCondition) { "" }
j
I'm guessing here you'd want
optional
to be null? Seems to me it would be a bit weird cause we're saying not initialized == null
l
Essentially expression defaults to null if not exhausted.
g
Because if without else is not an expression, use null as implicit default value doesn't look as good idea for me
r
For the same reason
val x: String?
doesn't default to
null
. Kotlin is all about being explicit.
👍 3