I expected that a Map is a Map, and the `in` opera...
# announcements
b
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
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
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
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
👍
b
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
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
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.