title: How to declare a function as a variable in Kotlin
body: <p>So I am trying to create a listener in Kotlin. I just want to pass a method that will be executed latter in my code. Like this:</p>
  
  <pre><code>override fun setButtonClickListener(listener: (text: String) -&gt; Unit) {
      this.listener = listener
  }
  </code></pre>
  
  <p>But, when I declare my listener, I must declare it like this:</p>
  
  <pre><code>private var listener : (text: String) -&gt; Unit = null!!
  </code></pre>
  
  <p>Otherwise my AS will complain. But this !! in a null object seams so weird. How should I declare this listener??</p>
  
  <p>Thanks!</p>