-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
  • 18,334
  • 9
  • 47
  • 62
VSB
  • 8,918
  • 12
  • 64
  • 128
  • 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
  • 18,334
  • 9
  • 47
  • 62