Kotlin: For-loop must have an iterator method - is this a bug?

try

for(p2 in 0 until list.count()) {
    ...
    ...
} 

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()

Tags:

Arrays

Kotlin