相关疑难解决方法(0)

find和firstOrNull有什么区别?

鉴于从Kotlin Koans中提取的以下代码:

fun Shop.findAnyCustomerFrom(city: City): Customer? {
    // Return a customer who lives in the given city, or null if there is none
    return customers.firstOrNull { it.isFrom(city) }
}
Run Code Online (Sandbox Code Playgroud)

我用自己的解决方案customers.find.两者都在koan场景中工作.

文档firstOrNullfind似乎非常相似.

这两个功能有什么区别?

collections kotlin

16
推荐指数
1
解决办法
4125
查看次数

标签 统计

collections ×1

kotlin ×1