It is pretty handy that the compiler automatically detects null
-Checks like these
val x : String? = getX()
if(x == null) return
x.trim() // <-- works
On the other hand the more useful functions doesn’t have this feature:
val x : String? = getX()
if(x.isNullOrBlank()) return
x.trim() // <-- will not compile since x is still potential null
Wouldn’t it be possible to mark such methods (like isNullOrBlank
) somehow so that the compiler knows that they are performing null-Checks?