Given the code below:
class Foo {
companion object {
lateinit var names: Array<String>
}
init {
names = arrayOf("George", "Keith", "Martha", "Margret")
}
}
If I created two instances of Foo
:
var foo1 = Foo();
var foo2 = Foo();
is names
going to be initialised/assigned twice, and therefore with any subsequent Foo
initialisation?
My intent is to have a simple static variable names
holding those predefined names.
Update:
This is assuming I do not want to have: var names: arrayOf("George", "Keith", "Martha", "Margret")
inside companion object.