Can Kotlin's isNullOrBlank() function be imported into xml for use with data binding

Android data binding still generates the Java code from the XML instead of the Kotlin code, once data binding will be migrated to generating Kotlin code instead of Java I believe we will be able to use Kotlin extension function in the XML, which will be really cool.

I am sure that gonna happen real soon as Google is pushing to Kotlin heavily. But for now, you have below

TextUtils.isEmpty() as mentioned by @Uli Don't forget to write an import.

The reason why you can't you use StringKt.isNullOrBlack in xml:

Below is the code from Kotlin String.kt

@kotlin.internal.InlineOnly
public inline fun CharSequence?.isNullOrEmpty(): Boolean {
    contract {
        returns(false) implies (this@isNullOrEmpty != null)
    }

    return this == null || this.length == 0
}

As you can see it is annotated with @kotlin.internal.InlineOnly which says the Java generated code of this method will be private.

InlineOnly means that the Java method corresponding to this Kotlin function is marked private so that Java code cannot access it (which is the only way to call an inline function without actual inlining it).

It means it can't be called from Java and as data binding generated code is in JAVA it can't be used in data binding either. Thumb rule is what you can access from JAVA you can use that in data binding if not just use the old Java way I would say.


TextUtils.isEmpty() should do what you want.