Order of init calls in Kotlin Array initialization

后端 未结 2 1819
轮回少年
轮回少年 2020-12-12 00:23

In the constructor of an Array is there a guarantee that the init function will be called for the indexes in an increasing order?

It would make sense but I did not f

2条回答
  •  爱一瞬间的悲伤
    2020-12-12 01:07

    Starting from the version 1.3.50 Kotlin has guaranteed sequential array initialization order in its API documentation: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/-init-.html

    The function init is called for each array element sequentially starting from the first one. It should return the value for an array element given its index.

提交回复
热议问题