title: kotlin verify input fields
body: <p>I'm moving from Java to Kotlin for my Android development. I want to check if a field in EditText is empty or not. So I've tried to make this:</p>
  
  <pre><code>override fun checkFields() {
  
    val username = username.text.toString().trim().takeUnless { username.text.isNullOrEmpty() } ?: presenter.usernameError()
    val password = password.text.toString().trim().takeUnless { password.text.isNullOrEmpty() } ?: presenter.passwordError()
  
    presenter.signInWithUsernameAndPassword(username as String,password as String)
  }
  </code></pre>
  
  <p>but there are two problems:</p>
  
  <ol>
  <li>it passes also to the <code>signInWithUsernameAndPassword</code> also if username/password is empty</li>
  <li><p>it crashes because gives me this error:</p>
  
  <p>java.lang.ClassCastException: kotlin.Unit cannot be cast to java.lang.String</p></li>
  </ol>
  
  <p>why? <code>takeUnless{}</code> converts String to Unit?</p>
  
  <p>Thanks</p>