“in ..” syntax considered harmful?

“in ..” syntax considered harmful?

Unlike my expectation,

a in b .. c

converted to

a <= b && b <= c

, it seems it is not implemented as what I said.

What I wrote at first was


when(a.compareTo(b)) { in 1..INT.MAX_VALUE -> //do something else -> // do other things }

and I found out

Integer.valueOf

and

IntIterator.next

consume every CPU power after profiled my code.

After googing I realized kotlin permits operator

<

or

>

unlike Java, and the revised one


when { a > b -> // do something else -> // do other things }

makes the program faster dramatically 🙂

submitted by /u/sixtyfifth_snow
[link] [comments]