Feature request: Safe navigation operator for Null checking (MyObject?.SomeProperty )
It would be nice to have the "Elvis" operator in MX2 to simplify property checking:
Current syntax examples: `If Myobject And Myobject.SomeNullableProperty
Local myVar:Float If Myobject myVar = Myobject.AFloatProperty`
New Syntax examples: `If Myobject?.SomeNullableProperty
Local myVar:= Myobject?.AFloatProperty`
I have the same thought. :)
?. called "safe navigation operator", it do null checks for us and return null instead of throw an NullPointerException, https://en.wikipedia.org/wiki/Safe_navigation_operator
Example:
Local name := article?.author?.name
If Not name Return
Elvis operator is ?:, it return right side only if left is null, (https://en.wikipedia.org/wiki/Elvis_operator)
Example:
Local name := article?.author?.name
If Not name Return
Also there is a ?? useful operator to simplify ? .. Else construction (but not only), https://en.wikipedia.org/wiki/Null_coalescing_operator.
Example:
Local title := customTitle ?? "Untitled"
Also I like the way Kotlin lang use ?: - we can write such code
val city = getCityById(100500) ?: return
assign value if it's not null or return - very short and readable.
http://kotlinlang.org/docs/reference/null-safety.html#safe-calls
I saw implementation for them in repo. Can't wait to try it out. :)
Finished.
Could be closed.