Smart cast to kotlin.String
The compiler knows that mTripStatus
cannot be null
if the if
condition is satisfied, so it performs a smart cast from String?
to String
. That's what allows html.replace("TRIP_STATUS_VALUE", mTripStatus)
to compile.
But note that this shouldn't be interpreted as a compiler warning. This is idiomatic Kotlin code.
This code:
var html :String = HTML
html = if (mTripStatus!=null) html.replace("TRIP_STATUS_VALUE", mTripStatus) else html
can be:
var html: String = html
mTripStatus?.let { html = html.replace("TRIP_STATUS_VALUE", mTripStatus) }