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

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

Ansible warning on jinja2 braces on when -

html - How to custom Bootstrap grid height? -