Hey guys. Anyone knows what’s the execution order ...
# announcements
w
Hey guys. Anyone knows what’s the execution order for init block and property?
Copy code
class A{
  val b:Int  = 0
  val a:Int
  init {
    a = 2
  }
}
Is there any order of a/b’s initialization? a first?
d
Code runs in the order it appears in the source code. So in your example the initializer for
b
would run first, then the
init
block.
w
But somehow I get some devices that a happens before b. 🤔 Complier optimization or something?
d
Can you show your actual code? With just plain ints there is no real initialization is there...
w
I add it in channel.