isEmpty所在位置是kotlin.text.isEmpty,其相關用法介紹如下。

用法:

fun CharSequence.isEmpty(): Boolean

如果此字符序列為空(不包含字符),則返回 true

例子:

import java.util.Locale
import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
fun markdownLink(title: String, url: String) =
    if (title.isEmpty()) url else "[$title]($url)"

// plain link
println(markdownLink(title = "", url = "https://kotlinlang.org")) // https://kotlinlang.org

// link with custom title
println(markdownLink(title = "Kotlin Language", url = "https://kotlinlang.org")) // [Kotlin Language](https://kotlinlang.org)
//sampleEnd
}

輸出:

https://kotlinlang.org
[Kotlin Language](https://kotlinlang.org)