Kotlin: For-loop must have an iterator method - is this a bug?
Your ArrayList
is of nullable type. So, you have to resolve this. There are several options:
for (p2 in list.orEmpty()) { ... }
or
list?.let { for (p2 in it) { }}
or you can just return an empty list
public fun findSomeLikeThis(): List<T> //Do you need mutable ArrayList here? = (Db4o.objectContainer()!!.queryByExample<T>(this as T) as Collection<T>)?.toList().orEmpty()
I also face this problem when I loop on some thing it is not an array.
Example
fun maximum(prices: Array<Int>){ val sortedPrices = prices.sort() for(price in sortedPrices){ // it will display for-loop range must have iterator here (because `prices.sort` don't return Unit not Array) }}
This is different case to this question but hope it help