is there a collection in kotlin like java's `Vecto...
# stdlib
b
is there a collection in kotlin like java's
Vector
which will default instantiate the instances? i want to create a collection of a generic type (from a class generic param) but don't want to have to pass in a lambda to tell the class how to default initialize. i.e.:
Copy code
class Foo<StatType> {
    val stats = Vector<StatType>(8)
}
p
As far as I know, java’s
Vector
does not create default instances for its elements. How would this work if
StatType
didn’t have default constructor? You can just write:
Copy code
List(8) { StatType() }
b
i can't do that because the generic isn't reified. and i assumed java would throw or something if it didn't have a default (it works with the vector, i didn't dig into how though)
p
`Vector`s constructor accepts
initialCapacity
. Size of the
Vector
will still be 0.
b
hmm. i know that with that initialization, i'm able to do
stats[index].member
and it works fine.
nope, sorry. i take that back.
you're right, the instance isn't there. so i guess i'm stuck with passing a builder or something either way
e
You need to pass a builder. You can use a functional type
() -> T
b
cool, that's exactly what i did. thanks.