Print length

Report a typo

We have a function printLength that prints to the console the length of a String:

fun printLength(s: String?) {
    if (!s.isBlankOrNull()) println(s.length)
}

Add a contract to the provided function isBlankOrNull, which implies that when the function returns false, the receiver is not null.

Sample Input 1:

Kotlin

Sample Output 1:

6
Write a program in Kotlin
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract

@OptIn(ExperimentalContracts::class)
fun String?.isBlankOrNull(): Boolean {

// Your code goes here

return this == null || this.isBlank()
}

Create a free account to access the full topic