How can you check, if a class has an initializer f...
# getting-started
h
How can you check, if a class has an initializer for a lateinit variable, when this class is passed as variable to another class?
Copy code
class Config {
    lateinit var s: String
}
class Consumer(val config: Config) {
    init {
         require(config::s.isInitialized)
    }
}
My current workaround is using an internal member function:
fun isInitialized() = ::s.isInitialized
and call this function in
require
.
a
Copy code
class Config(var s: String)
can ensure that
s
must have a value
or use
Delegates.notNull<T>()
more elegantly
Copy code
class Config {
  var s: String by Delegates.notNull()
}
m
@Arxing Lin what is the point of
Delegates.notNull
? How is it different from lateinit var?