0

我在 Android Studio 中遇到过 Kotlin 的有趣行为。当我尝试动态记录提供的索引为 -1 且数组为空的数组元素时,程序会在模拟器中冻结但从不抛出错误。

示例代码:

val myObjects = mutableListOf<MyObject>()
val objIndex = -1
...
Log.d(TAG, "Non-existent element: ${myObjects[objIndex].myValue}") //stuck here, doesn't move past

是什么导致 Kotlin 代码执行中出现这种看似无限循环或暂停的情况?

4

0 回答 0