title: Kotlin :Wrapped into a reference object to be modified when captured in a closure
body: <p>I am implementing Firebase on android using kotlin.</p>
  
  <p>as the <code>FirebaseInstanceId.getInstance().token</code> is depriciated, I am using the following function inside the companion object of my <code>MyFirebaseMessageService</code> class to get the token:</p>
  
  <pre><code>companion object
  {
    fun grabFcmToken():String?
    {
      var s:String?=null
      FirebaseInstanceId.getInstance().
      instanceId.addOnCompleteListener {task -&gt;
      if (task.isSuccessful)
       {
          s=task.result!!.token
          Log.i("token used is ", s)
       }
       else
        {
          throw Exception("Can't get firebase token")
        } 
      }
      Log.i("To be returned token ", s)
      return s
    }
  }
  </code></pre>
  
  <p>Android Studio highlights <code>s</code> as <code>Wrapped into a reference object to be modified when captured in a closure</code></p>
  
  <p>Upon the execution of <code>grabFcmToken()</code> the first log prints the token successfully, but the second log has a <code>java.lang.NullPointerException: println needs a message</code> indicating that s has the value <code>null</code> and hence it's value is unchanged.</p>
  
  <p>how may i modify <code>s</code> such that the captured token is being reflected in it?</p>