this ```infix fun ArrayList<*>.resize(newSiz...
# getting-started
e
this
Copy code
infix fun ArrayList<*>.resize(newSize: Int) {
    when {
        size > newSize -> for (i in newSize until size) pop()
        newSize > size -> when(get(0)){
            is Dbvt.StkNN -> for (i in size until newSize) add(Dbvt.StkNN())
            is DbvtNode -> for (i in size until newSize) add(DbvtNode())
        }
    }
}
complains at
add
Out-projected type 'kotlin.collections.ArrayList<*> /* = java.util.ArrayList<*> */' prohibits the use of 'public open fun add(element: E): Boolean defined in java.util.ArrayList```
i
star-projection is equivalent to
out Any?
, thus you cannot put anything back to this list.
e
Copy code
infix fun <T>ArrayList<T>.resize(newSize: Int) {
    when {
        size > newSize -> for (i in newSize until size) pop()
        newSize > size -> when(get(0)){
            is Dbvt.StkNN -> for (i in size until newSize) add(Dbvt.StkNN() as T)
            is DbvtNode -> for (i in size until newSize) add(DbvtNode() as T)
        }
    }
}
trying this at the moment..
i
I doubt this function would produce correct result if someone calls it on ArrayList<Int>.
e
yeah, but I need it only for a small range of types
i
Do these types have a common supertype?
e
unfortunately no