ForEachOnRange on Range.toList()
roman-wedemeier opened this issue · 0 comments
roman-wedemeier commented
When i write
fun main() {
(0..9).toList().forEach { println(it) }
}
Then the part (0..9).toList()
is marked with the following message:
detekt - ForEachOnRange: Using the forEach method on ranges has a heavy performance cost. Prefer using simple for loops.
I would expect, that the toList()
Method creates a List<Int>
, where i can do the forEach
safely.
When i write
fun main() {
val list = (0..9).toList()
list.forEach { println(it) }
}
no warning comes up (despite another warning complaining the magic number 9, but this is another Story).
Did i understand something wrong?