I really don’t see how guard syntax better in this...
# announcements
g
I really don’t see how guard syntax better in this case. Yes, smart cast doesn’t work for all the cases, in this case you just can use this:
Copy code
val unwrapped = foo?.something
if (unwrapped != null) {
  unwrapped.soSomething()
} else {
   otherStuff()
}
But you need this only when smartcast doesn’t work for you Also you can do something like this:
Copy code
val unwrapped = foo?.something ?: return otherStuff()
// or just
val unwrapped = foo?.something ?: return
// or throw error
val unwrapped = foo?.something ?: error("foo is null")
// and now you can  use unwrapped as non-null
unwrapped.soSomething()