IntArray vs Array in Kotlin

后端 未结 3 1551
忘掉有多难
忘掉有多难 2020-11-30 02:29

I\'m not sure what the difference between an IntArray and an Array is in Kotlin and why I can\'t used them interchangeably:

3条回答
  •  被撕碎了的回忆
    2020-11-30 02:31

    Arrays in Kotlin are classes (not "special" types like Java).

    Kotlin's stdlib provides special purpose classes for JVM primitive arrays in order to improve Java language integration and performance.

    The rule of thumb would be to use Array except if it cause a problem when mixing with existing Java code, or should be called from Java classes. For the record, I never had to use IntArray.

    You can check the Language's documentation regarding this matter here: https://kotlinlang.org/docs/reference/basic-types.html#arrays

提交回复
热议问题