Any way to tell Kotlin compiler that prior callable function already did a check for null -


if have code fragment like

val mynullablestring : string? val resultingstring = if (mynullablestring.isnullorblank())  mynulldefaultstring else string.format(mynullablestring!!, someotherstring) 

i have use mynullablestring!! in string.format() since compiler not able figure out isnullorblank() includes null-check. correct or there way tell compiler function infer instance not null?

didn’t see mentions there way tell such info compiler, here workaround: having function returning null if string empty , use let?.{} after that

inline fun string?.nullifblank(): string? = if (this?.isblank() ?: true) null else  val resultingstring: string = mynullablestring.nullifblank()?.let {     string.format(it)  } ?: mynulldefaultstring 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -