【发布时间】:2017-12-26 12:54:29
【问题描述】:
我刚刚查看了Kotlinstandard library,发现了一些名为componentN 的奇怪扩展函数,其中 N 是从 1 到 5 的索引。
所有类型的原语都有函数。例如:
/**
* Returns 1st *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun IntArray.component1(): Int {
return get(0)
}
我看起来很奇怪。我对开发人员的动机感兴趣。打电话给array.component1()而不是array[0]更好吗?
【问题讨论】:
标签: arrays kotlin kotlin-extension