date updated | date created | date modified |
---|---|---|
2021-11-02 20:24 |
Friday, November 19th 2021, 2:00:25 pm |
Tuesday, November 2nd 2021, 8:26:16 pm |
Topic: #kotlin
Tags: #review #pn_2_1
Links: [[Type in Kotlin]]
Date Created: 02-11-21
[[Arrays in Kotlin]] are invariant, this means that the [[Type]] cannot be changed.
If we want to have dynamic array [[Type|types]] then we should use a [[Generics]], more precisely [[Generics in Kotlin#Type Projections|Type Projections]].
With a [[Constructor]]
val tab = Array<Type>(size) { values}
With a [[Factory]]1
val tab = arrayOf(val1, val2, ...)
tab.get(indexOfDesiredItem)
tab[indexOfDesiredItem]
Footnotes
-
note that this link might talk about factory from another language which might not be the same in Kotlin ↩