Try the below. It won’t compile, as it will force you to add this?.check().

private fun String?.isGood(): Boolean {
return !this.isNullOrEmpty() && this.check()
}

But if you try the below, it compiles.

private fun String?.isGood(): Boolean {
return this != null && this.check()
}

The fact is internal to !this.isNullOrEmpty is inclusive of this != null but is not realized by the compiler. Hopes this clarifies.

Written by

Passionate about learning, and sharing mobile development and others

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store