This should be trivial. Kotlin has an ArrayList with a constructor "initialCapacity"
If I have this test case;
class ArrayListTest : TestCase() {
@Test
fun testArrayList() {
val test = ArrayList<Int>(12)
test[3]=5
}
}
I get the exception
java.lang.IndexOutOfBoundsException: Index 3 out of bounds for length 0
Running in debug confirms that although the ArrayList is created, its size is zero.
The docs say there's limited functionality for controlling capacity because the backing array is resizable itself, but this doesn't seem to be happening. Even if I use index 0 I get the out of bounds exception.
I tried running an update on the offchance. I'm running Android Studio Arctic Fox 2020.3.1 Patch 3, of Oct 1st 2021.
Has anyone else encountered and resolved this?
Edit: hmm. test.add(5) lets you append, which is fine for most cases. I'm leaving the question up because it seems the original approach should work.