Tag: 迭代

Kotlin:迭代一个具有解构条目的地图是不是可能的? 错误?

看起来就像最新的Kotlin更新一样,您不能再通过具有解构Entry地图来迭代。 例如: val map = HashMap() for ((i, s) in map) { // compiler error here … // code } 编译器错误是For-loop range must have an iterator() method 此function以前按预期工作,遍历地图中的每个条目。 我也尝试使用map.entries和map.entrySet() (不建议使用)和这些: 现在迭代地图的习惯用法是什么? 这是一个错误?

迭代:Kotlin是否有像Python一样的“枚举”function?

在Python中,我可以写: for i, element in enumerate(my_list): print i # the index, starting from 0 print element # the list-element 我怎样才能在Kotlin写这个?