jro
11/11/2020, 9:03 AMfoo
being null
inside the init block expected behavior? Doesn't seem right for a property that's declared not null. Printing foo
directly results in an error.
Run code in kotlin playgroundephemient
11/11/2020, 9:16 AMjro
11/11/2020, 9:17 AMephemient
11/11/2020, 9:18 AMjro
11/11/2020, 9:20 AMephemient
11/11/2020, 9:23 AMprintln(foo)
, it's statically resolved to fun println(message: String)
, where Kotlin applies a null checkephemient
11/11/2020, 9:23 AM"$foo"
, there's no null check involved thereephemient
11/11/2020, 9:24 AMjro
11/11/2020, 9:24 AM"$foo"
doesn't seem to work in the init block.ephemient
11/11/2020, 9:25 AMephemient
11/11/2020, 9:25 AMjro
11/11/2020, 9:26 AMjro
11/11/2020, 9:26 AMAnimesh Sahu
11/11/2020, 9:50 AMAnimesh Sahu
11/11/2020, 9:51 AMpavi2410
11/11/2020, 7:32 PMephemient
11/12/2020, 12:12 AMvar foo: String by Delegates.notNull()
. the downside to both is that the compiler stops enforcing that the field is initialized in init
, and every single access has to pay the cost of checking if it's initializedAbel
11/23/2020, 6:16 PM