Whats the best way in kotlin for an null object’s toString() method to return an empty string instead of “null”

How about:

nullable?.toString() ?: ""

or as Alexander Udalov suggested:

nullable?.toString().orEmpty()

Which one can wrap in an extension method:

fun Any?.toStringOrEmpty() = this?.toString() ?: ""

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)