https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
p

Patrick Jackson

03/13/2019, 2:02 PM
Are top level variables initialized differently in kotlin native? I have code that runs on jvm fine, but in native I get a bad_access for a val. Given: class A(private var b: B) { fun foo() { b.bar() } } val b = B() val a = A(b) I will get a bad_access (null pointer) on the instance of b when calling b.bar() in foo(). Changing a to use
by lazy
fixes the problem.
o

olonho

03/13/2019, 3:52 PM
Are all declarations in the same file?
p

Patrick Jackson

03/13/2019, 4:50 PM
no
o

olonho

03/13/2019, 5:11 PM
so it’s where problem came from - there’s no order guarantees between files
p

Patrick Jackson

03/13/2019, 5:33 PM
thank you for clarifying
3 Views