给定此代码
myValue.number?.setScale(2).toString() ?: ""
I want it to return ""
if number is null
. But it just returns null
. What concept did I not grasp here?
给定此代码
myValue.number?.setScale(2).toString() ?: ""
I want it to return ""
if number is null
. But it just returns null
. What concept did I not grasp here?
There is
toString
for nullable types that returns"null"
if reference (or expression) is null, so in your case,?: ""
expression is unreachable. Add another null-safe call operator