weraeducation.blogg.se

Kotlin ranges
Kotlin ranges




kotlin ranges kotlin ranges

The same compilation behavior is seen for simple decrementing progressions as well (e.g.

kotlin ranges

It allocates a couple primitives and has a couple if-checks, but is otherwise fairly simple. Given that the compiler can optimize ranges, which of the following range-based for-loops do you think is the most efficient? // Option 1 No allocations necessary! Range Against The Machine In other words, when endInclusive urlThumbĪgain, the above compiles to a series of simple conditionals. That's because IntRange is defined by its minimum start and its maximum endInclusive values. If you think the answer is 123321, guess again. Pop quiz: What does the following code output? (1.3).forEach(System.out::print) Here are a few interesting aspects of Kotlin ranges, some of which I've found to be less-than-intuitive.






Kotlin ranges