Similar with ``` class Foo { lateinit var i: Integ...
# getting-started
p
Similar with
Copy code
class Foo { lateinit var i: Integer }
var foo= Foo()

foo.i.isInitialized // =>
// error: unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 
// @SinceKotlin @InlineOnly public val @receiver:AccessibleLateinitPropertyLiteral KProperty0<*>.isInitialized: Boolean defined in kotlin

foo::i.isInitialized // ->error: backing field of 'var i: Integer' is not accessible at this point
Help, please.
s
I can’t be 100% sure but I think backing field access is restricted to within the class or file
Copy code
class Foo {
  lateinit var i: String

  fun bar() {
    if (::i.isInitialized) {

    }
  }
}

lateinit var j: String

fun qaz() {
  if (::j.isInitialized) {

  }
}
both are valid ways of using
isInitialized
ancillary to your initial question, you shouldn’t be using
Integer
unless strictly necessary - use
Int
instead, and try to just set a default value
😑 1
p
Thank you Shawn.