``` data class User(val name: String, val email: S...
# getting-started
s
Copy code
data 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?
d
You might be able to see this in the bytecode.
l
I’d bet on (1) data class arguments’ positioning
k
I'd bet (2) actually, but I'm not at a computer to test 😔
s
Copy code
data 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:
Copy code
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!
l
return new Test(var0, var1);
var0 = getOne()
one
is the first being passed to the constructor, even if you use named parameter, decompiled code re-order them
s
@Luca Nicoletti to clarify, I meant the order of execution of the functions
getOne()
and
getTwo()
l
Oh, sorry, mis-understood then 🙂
👍 1
k
It would be pretty bad if they messed that up 😄
s
I agree, but it was not obvious from the docs 😄
m
https://pl.kotl.in/rtLhUzrvd Execution is in order of named arguments. Why look at bytecode 😄 ?
1