Animesh Sahu
11/09/2020, 5:52 PMObject declaration's initialization is thread-safe and done at first access.But the following code
object TestObject {
val a = "hello"
fun b(): Nothing = TODO()
}
decompiles as follows:
public final class TestObject {
@NotNull
private static final String a;
public static final TestObject INSTANCE;
@NotNull
public final String getA() {
return a;
}
@NotNull
public final Void b() {
boolean var1 = false;
throw (Throwable)(new NotImplementedError((String)null, 1, (DefaultConstructorMarker)null));
}
private TestObject() {
}
static {
TestObject var0 = new TestObject();
INSTANCE = var0;
a = "hello";
}
}
Tested with/without property and with/without function declaration. Same behavior static initialization, is the docs outdated?Zach Klippenstein (he/him) [MOD]
11/09/2020, 5:54 PMZach Klippenstein (he/him) [MOD]
11/09/2020, 5:55 PMcompileOnly
dependency on some library and then run some code that tries using some API from that library – an exception will be thrown the first time you try accessing the API.Animesh Sahu
11/09/2020, 6:07 PMAnimesh Sahu
11/09/2020, 6:07 PMAnimesh Sahu
11/09/2020, 6:08 PMZach Klippenstein (he/him) [MOD]
11/09/2020, 7:23 PMNico
11/11/2020, 1:33 PMlazy
. This will also make it explicit and readable