Gamar Mustafa
06/05/2024, 9:08 AMbylazy
doesn't work with var
? I know we have lateinit
for that case, but what I am wondering about are the restrictions for var
with bylazy
. It would be nice to have a property that gets initialized the first time you access it, and then you can change its value laterYoussef Shoaib [MOD]
06/05/2024, 9:34 AMlazy
is especially optimized for single initialisation and is made to be safe to access from many threadsRonny Bräunlich
06/05/2024, 10:39 AMby lazy
. E.g. this class:
class MyTestClass {
val foo by lazy { "baz" }
}
results in bytecode that doesn't have a String propery, but one of type `Lazy`:
public final class MyTestClass {
@NotNull
private final Lazy foo$delegate;
@NotNull
public final String getFoo() {
Lazy var1 = this.foo$delegate;
Object var3 = null;
return (String)var1.getValue();
}
...
}
That shows that you're not supposed to replace the Lazy
delegate that is present in the bytecode.Youssef Shoaib [MOD]
06/05/2024, 10:55 AMsetValue
and that's it