Kotlin docs say *`i in 1..4`* is equivalent of `1 ...
# announcements
v
Kotlin docs say
i in 1..4
is equivalent of
1 <= i && i <= 4
, but is it really on the bytecode level? Doesn't range expression generate an additional range object?
e
nope, you can dump the bytecode and check for yourself
l
You can check the Bytecode via "Tools" -> "Kotlin" -> "Show Kotlin Bytecode" in IntelliJ. This will open a window containing the Bytecode. From there you may already see what happened. You could click on "Decompile" and it will show you some Java Class created out of that Bytecode, containing an ordinary for loop (with no additional range objects or the like)
❤️ 1
v
Thank you!
n
the for-in range is what's called "intrinsic", meaning it does compile directly to bytecode without an object allocation. FWIW, it was relatively recent...I'm having trouble finding it now, but I think it was in 1.3.* somewhere.
👍 1