sandi
09/04/2019, 4:22 PMdata class User(val name: String, val email: String)
val user: User get() = User(email = getEmail(), name = getName())
What is the order of execution here? Do named arguments get resolved (1) according to the data class argument positioning or (2) when creating the object with named arguments?Dominaezzz
09/04/2019, 4:25 PMLuca Nicoletti
09/04/2019, 4:27 PMkarelpeeters
09/04/2019, 4:29 PMsandi
09/04/2019, 4:29 PMdata class Test(val one: String, val two: String)
fun testFunc(): Test {
return Test(two = getTwo(), one = getOne())
}
fun getOne(): String {
return "Hello ${1}"
}
fun getTwo(): String {
return "Hello ${2}"
}
decompiles to:
public final class TestKt {
@NotNull
public static final Test testFunc() {
String var10002 = getTwo();
String var0 = getOne();
String var1 = var10002;
return new Test(var0, var1);
}
@NotNull
public static final String getOne() {
return "Hello 1";
}
@NotNull
public static final String getTwo() {
return "Hello 2";
}
}
Seems like it’s actually (2) @Luca Nicoletti, thanks for the tip @Dominaezzz!Luca Nicoletti
09/04/2019, 4:33 PMreturn new Test(var0, var1);
Luca Nicoletti
09/04/2019, 4:34 PMvar0 = getOne()
Luca Nicoletti
09/04/2019, 4:35 PMone
is the first being passed to the constructor, even if you use named parameter, decompiled code re-order themsandi
09/04/2019, 4:35 PMgetOne()
and getTwo()
Luca Nicoletti
09/04/2019, 4:35 PMkarelpeeters
09/04/2019, 4:36 PMsandi
09/04/2019, 4:38 PMmolikuner
09/04/2019, 8:50 PM