E.g. the stdlib defines the following function:
fun CharSequence?.isNullOrBlank(): Boolean
You can take a reference to this extension function like this:
val isNullOrBlankFn = CharSequence?::isNullOrBlank
The type of isNullOrBlankFn
is, as you'd expect, (CharSequence?)->Boolean
.
You can also refer to isNullOrBlank like this:
val isNullOrBlankFn = CharSequence::isNullOrBlank
But that gives isNullOrBlankFn
the type (CharSequence)->Boolean
-- it cannot be applied to nullable CharSequences.
This is allowed because CharSequence
is a subtype of CharSequence?
, and therefore a CharSequence
can be passed wherever CharSequence?
is allowed.
This also lets you refer to the isNullOrBlank
extension function like this: String?::isNullOrBlank
or even String::isNullOrBlank
.
Corresponding issue: https://youtrack.jetbrains.com/issue/KT-19140