var list = mutableListOf<String>()
var data = list.plusElement("a").plusElement("b").plusElement("c")
log.d(TAG,list.size.toString())
log.d(TAG,data.size.toString())
添加完元素之后打印
“0”
“3”
这是因为list.plusElement() 返回添加后的集合
/**
* Returns a list containing all elements of the original collection and then the given [element].
*/
@kotlin.internal.InlineOnly
public inline fun <T> Collection<T>.plusElement(element: T): List<T> {
return plus(element)
}
要注意,使用之前的list size会是0