allan.conda
06/08/2022, 10:13 AMlet
hides the uninitialized variable being null. Is there an explanation regarding this? Seems Kotlin (1.6.21) is not null-safe in this situation.
class SomeClass { // extremely minified code
val foo = let { bar } // compile error (almost broke production but my unit test captured it)
// val foo = bar // compile error (safe!)
val bar = true
}
ephemient
06/08/2022, 10:17 AMclass SomeClass {
val foo = bar()
val bar = true
private fun bar() = bar
and see an uninitialized variable there as wellallan.conda
06/08/2022, 11:25 AMKlitos Kyriacou
06/08/2022, 1:33 PMSomeClass().foo
is initialized to false
. I thought this discussion is saying it's uninitialized.Ruckus
06/08/2022, 2:29 PM0
, for `boolean`s it will be false
, and for references it will be null
.
Essentially, when you declare a value on the JVM, it has memory allocated for it and all the bits are set to 0
, which is interpreted as I mentioned above. (That implementation detail will eventually be important when Project Valhalla ever happens.)allan.conda
06/08/2022, 2:36 PMList<T>
type which is null if uninitialized.