gjesse
09/22/2017, 3:27 AMList<List<String>>
, found List<Any>
kotlin
val hmm: List<List<String>> = listOf(
listOf("a"),
listOf("b")
)
val hmm2: List<List<String>> = hmm + listOf("c")
edwardwongtl
09/22/2017, 3:29 AMhmm
is of type List<List<String>>
while listOf("c")
is List<String>
, so the end result become List<Any>
edwardwongtl
09/22/2017, 3:30 AMval hmm2: List<List<String>> = hmm + listOf(listOf("c"))
gjesse
09/22/2017, 3:30 AMgjesse
09/22/2017, 3:30 AMgjesse
09/22/2017, 3:30 AMgjesse
09/22/2017, 3:30 AMedwardwongtl
09/22/2017, 3:31 AMkarelpeeters
09/22/2017, 8:46 AMval list = listOf("a")
println(list + "b")
prints ["a", "b"]
.edwardwongtl
09/22/2017, 9:00 AMlistOf("c")
, since it is a collectionedwardwongtl
09/22/2017, 9:00 AMpublic operator fun <T> Collection<T>.plus(elements: Iterable<T>): List<T> {
if (elements is Collection) {
val result = ArrayList<T>(this.size + elements.size)
result.addAll(this)
result.addAll(elements)
return result
} else {
val result = ArrayList<T>(this)
result.addAll(elements)
return result
}
}
karelpeeters
09/22/2017, 9:09 AM+
is both append and merge, and the latter has precedence because the types are more specific.gjesse
09/22/2017, 12:56 PM