https://kotlinlang.org logo
#coroutines
Title
# coroutines
d

Dico

06/06/2019, 4:24 PM
Is there a particular reason why
AtomicInt
from kotlinx:atomicfu doesn't declare these:
operator fun plusAssign
(+=)
operator fun minusAssign
(-=)
operator fun inc
(++)
operator fun dec
(--) In Java, these couldn't be atomic, but since you can implement them yourself, they would be. For
inc
and
dec
I guess it might be because they would have to return AtomicInt, instead of Int. Asking here because I didn't see an atomicfu channel.
r

Ruckus

06/06/2019, 4:29 PM
For
inc
and
dec
, it would violate:
The
inc()
and
dec()
functions must return a value, which will be assigned to the variable on which the
++
or
--
operation was used. They shouldn't mutate the object on which the
inc
or
dec
was invoked.
(Emphasis added) https://kotlinlang.org/docs/reference/operator-overloading.html
d

Dico

06/06/2019, 4:29 PM
maybe there should be incAssign then 😂
alright, so it wouldn't work for those. Maybe that's a reason not to do it for the other two.
r

Ruckus

06/06/2019, 4:30 PM
There was a discussion about that a while ago in #language-proposals: https://kotlinlang.slack.com/archives/C0B9K7EP2/p1558292249060600
👍 1
(Speaking of channels, I'm not sure #coroutines was the best place for your question)
d

Dico

06/06/2019, 4:31 PM
I know kotlinfu as used extensively by the coroutines library, I didn't find something more adequate.
r

Ruckus

06/06/2019, 4:33 PM
The question itself has nothing to do with coroutines, so it may have fit better somewhere like #general, as it more about general Kotlin language functionality and design. Not a huge deal, but good to keep in mind for the future.
👍🏻 1
5 Views