-3

Can below snippet be written in shorter form in Kotlin using ! or ? operators:

val acct: GoogleSignInAccount?  = result.signInAccount
if (acct != null && acct.displayName != null)
    MagicToast.showSuccess(this, "Account Name: " + acct.displayName)
earthw0rmjim
  • 19,027
  • 9
  • 49
  • 63
VSB
  • 9,825
  • 16
  • 72
  • 145
  • you can just check the documentation for these kind of questions. It's all explained very well – Tim Nov 05 '18 at 14:38

1 Answers1

5
acct?.displayName?.let {
    MagicToast.showSuccess(this, "Account Name: $it")
}

Depending on your use case acct might be replaced with result.signInAccount.

earthw0rmjim
  • 19,027
  • 9
  • 49
  • 63