Closed
Description
In Kotlin, I have been used to arg ?: return
to check if function argument is null or some other variable is null. If that's the case, return immediately. In android this was really helpful where I did context ?: return
in Android apps.
I tried doing the same with ?? operator but I wasn't successful.
Like for ScrollController? _scrollController
data member, I want to do
final scrollController = _scrollController ?? return
This basically means if variable is null, return or set the value as final where object is non-null.
As far as the feature goes, it works for throws
as well. Ref: https://kotlinlang.org/docs/null-safety.html#elvis-operator