Let us move to thread, as this seems to cause quit...
# announcements
d
Let us move to thread, as this seems to cause quite a lot of clutter in global channel.
Now you're calling sequence of
plus
on
1000
instead of a whole hours-millis value. This is because dot-call
.
takes precedence over multiplication: https://kotlinlang.org/docs/reference/grammar.html#precedence This works as expected for me:
Copy code
val millis: Long = (calendar.get(Calendar.HOUR_OF_DAY).toLong() * 60 * 60 * 1000)
        .plus(calendar.get(Calendar.MINUTE).toLong() * 60 * 1000)
        .plus(calendar.get(Calendar.SECOND).toLong() * 1000)
        .plus(calendar.get(Calendar.MILLISECOND).toLong())

 val millis2: Long = calendar.get(Calendar.HOUR_OF_DAY).toLong() * 60 * 60 * 1000 +
        calendar.get(Calendar.MINUTE).toLong() * 60 * 1000 +
        calendar.get(Calendar.SECOND).toLong() * 1000 +
        calendar.get(Calendar.MILLISECOND).toLong()

 Assert.assertEquals(millis, millis2)
@alvico
I don't think Kotlin is much different from other languages here. If you have some proposals regarding our grammar, feel free to share them in #C0B9K7EP2 or in our tracker (kotl.in/issue)
a
Well it's the first language that I've found that multiline sum doesn't work :S
something I can do in java without any problems
and the fact that it compiles and executes is very annoying. what one would expect of this operation
d
It certainly works, as I've demonstrated above. Because users can override operators, in general case one can expect anything from such operation (e.g. such constructions make perfect sense for DSLs). As I've said, for primitive types we could do better and report that expression is unused. You can watch for updates on this ticket https://youtrack.jetbrains.com/issue/KT-12073
a
I'm happy with a warning
Sorry if I sounded a bit harsh, was frustrated after a whole day debugging a simple operation
I just couldn't imagine that a primitive operation wouldn't work in multiline sintax
d
was frustrated after a whole day debugging a simple operation
Yep, I certianly understand it. Sorry for that 🙂
a
np, thanks for the quick answer and feedback anyway
p
It's a best practice to end multiline math operations with an operator so that you know that there is another line coming. So I am ok with it working this way. An IntelliJ warning on the line with the unused expression would be a welcome addition though.
âž• 2