title: Kotlin - Is it possible to initialize companion object before the init block in a class?
body: <p>Is it possible to initialize an <code>companion object</code> before the <code>init</code> block in a Kotlin class? If so, how? If not, is there a way to accomplish the same thing. </p>
  
  <p>I have the following scenario,</p>
  
  <pre><code>class A(val iname: String) {
    init {
      foo.add(this)
    }
  
    companion object B {
      @JvmField val STATIC = A("hi")
      @JvmField val foo = mutableListOf&lt;A&gt;()   
    }
  
    fun printAllStatics() {
      for (a in foo) {
        print(a.iname)
      }
    }
  }
  </code></pre>
  
  <p>and calling <code>printAllStatics</code> causes a null-pointer exception.</p>