<https://medium.com/mobile-app-development-publica...
# feed
m
People tend to forget about extension functions. What do you think about these alternatives:
fun Any?.isNull() = this == null
and
fun Any?.isNotNull() = this != null
. That way you can assert any nullable type in a more readable way (the Kotlin way IMHO)
Copy code
val a: String? = null
val b: String? = ""

if(a.isNull() && b.isNotNull()) {
 ...
}
You can also add contracts to enable smart casts:
Copy code
fun Any?.isNull(): Boolean {
 contract {
        returns(true) implies (this == null)
    }
 return this == null
}
*Note: contracts are experimental.