title: Kotlin: Initialize class attribute in constructor
body: <p>I create a Kotlin-class with a class attribute, which I want to initialize in the constructor:</p>
  
  <pre><code>public class TestClass {
  
      private var context : Context? = null // Nullable attribute
  
      public constructor(context : Context) {
         this.context = context
      }
  
      public fun doSomeVoodoo() {
         val text : String = context!!.getString(R.string.abc_action_bar_home_description)
      }
  }
  </code></pre>
  
  <p>Unfortunately I have to declare the attribute as Nullable with the "?" sign, although the attribute will be initialized in the constructor. Declaring this attribute as Nullable-attribute makes it always necessary to force an NonNull-value with "!!" or to provide a Null-check with "?". </p>
  
  <p>Is there any way to avoid this, if the class attribute will be initialized in the constructor? I would like to appreciate a solution like this one:</p>
  
  <pre><code>public class TestClass {
  
      private var context : Context // Non-Nullable attribute
  
      public constructor(context : Context) {
         this.context = context
      }
  
      public fun doSomeVoodoo() {
         val text : String = context.getString(R.string.abc_action_bar_home_description)
      }
  }
  </code></pre>