https://kotlinlang.org logo
#announcements
Title
# announcements
b

brett.wooldridge

05/24/2017, 6:24 AM
I expected that a Map is a Map, and the
in
operator would be consistently interpreted as
containsKey(..)
. The fact that it does not cost me over an hour of debugging, and I think is a surprising result for users. I would expect to be able to switch a collection between
HashMap
,
ConcurrentHashMap
, ... any
Map
and have the code behave consistently.
a

Andreas Sinz

05/24/2017, 6:58 AM
brett.wooldridge: I think its neither of both. The
in
operator is mapped to
contains()
in kotlin. So the problem with ConcurrentHashMap is, that it defines its own legacy
contains()
which calls
containsValue()
. There is not really a way to override the behaviour of
ConcurrentHashMap.contains()
outside of the class itself
m

mg6maciej

05/24/2017, 7:03 AM
Please report this in kotl.in/issue. It at least deserves an inspection warning in IDE. Maybe there is something that can be done in the language for this special case, but I wouldn't expect this.
As a side note: tests help. 🙂
b

brett.wooldridge

05/24/2017, 7:19 AM
ok
A warning would have helped.
But if the stdlib can do an instanceof equivalent, that would be great.
KT-18053 Unexpected behavior with "in" infix operator and ConcurrentHashMap.
m

mg6maciej

05/24/2017, 7:26 AM
👍
b

brett.wooldridge

05/24/2017, 7:27 AM
By the way, I love the bejesus out of Kotlin. Been using it for ~8 months and I look forward to opening the IDE everyday.
Doing server-side greenfield development.
m

mg6maciej

05/24/2017, 7:29 AM
You may want to send it directly to #random instead of in thread so more people see it. JB devs like to see happy users 🙂
b

brett.wooldridge

05/24/2017, 7:30 AM
Hard to resist the temptation to go back and rewrite something that is already working every time I learn something new. 🙂
BTW, I'm the guy who is implementing daemon-resident Kotlin compilation support in Buck Build. 4 months in the making, but it should drop today or tomorrow! https://github.com/facebook/buck/pull/1283
If you guys aren't using Buck, I highly recommend it. Incremental CLI compilation times of like 0.1 seconds, prompt-to-prompt with single digit number of files changed.
4 Views