Is there "toStringOrNull"? I want to run toString() to a nullable string but I want to return null i...
k
Is there "toStringOrNull"? I want to run toString() to a nullable string but I want to return null if the value was null
l
variable?.toString()
๐Ÿ‘ 7
thank you color 1
โ˜๏ธ 4
โž• 3
l
?: "null"
๐Ÿ˜„
z
If toString is called on null variable it returns "null" string
โž• 2
h
Wouldn't
variable.toString()
enough as toString returns null anyway if the variable is null?
s
@Hassaan No, if
variable
is of type
String?
you canโ€™t call it this way because itโ€™s unsafe.
๐Ÿ‘ 1