You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
@imrhk, I think the discussion in #2025 covers this issue to a very high degree. So perhaps it would be useful to close this issue, and take the discussion in #2025 instead?
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 didcontext ?: 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 dofinal 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-operatorThe text was updated successfully, but these errors were encountered: