Let's say I have these 2 Java methods: `public Str...
# announcements
d
Let's say I have these 2 Java methods:
public String get(Integer key) {...}
public String get(int key) {...}
How can I call one of these without running into overload resolution ambiguity?
d
I think, with a nullablilty hack you can call the first one. Not sure how to call the second one.
d
ah that does work, I want to call the second one though 😅
k
So
get(5)
picks the first one as well?
d
that's illegal
k
Right 🤦‍♂️. What does
val f: (Int) -> String = ::get
do? Also illegal?
d
The concrete use case is that I want to call
remove(key, value)
on a
Int2ObjectOpenHashMap
from fastutil
d
Ha! Beat me to it.
d
Also illegal
I can do
get(5 ?: null)
or
get(5 as Int?)
but that doesn't call the one I want to call
k
There's reflection and creating a Java wrapper but you know about those simple smile
d
I can create a Java utility function I guess..
k
Exact same problem here (it's even fastutil): https://stackoverflow.com/q/37625599/5517612 It looks like there was a solution back then, maybe it's a regression?
d
Hmm, something weird seems to be happening here
```
Copy code
public static <V> boolean remove(Int2ObjectMap<V> map, int k, V v) {
        return map.remove(k, v);
    }

    public static <V> boolean remove(Int2ObjectMap<V> map, Integer k, V v) {
        return map.remove(k, v);
    }
I made these and I can call the primitive one from Kotlin
but not the member method
d
Same project maybe. 🤷🏼
d
I think it may be because of inheritance
the problem doesn't exist with
put
, which has the same overload ambiguity
making very little sense
thanks for the help to you both
k
I think there's a document somewhere specifying the exact resolution order/steps, but I can't seem to find it. I'll search when I'm on a pc.
Do let us know if you find a solution, now I'm interested!
d
I have no answer to why there's an error calling
remove
but not
put
I am adding a wrapper function though to make sure it calls the right one
Today I found out that comparing equality of inline classes causes both to be boxed when looking at the bytecode
😮 1
k
Haha why would that happen!?
d
so I lost some trust in the Kotlin compiler's decision making
They fixed this for next version though I think
k
I feel like inline classes are still very brittle, especially around delegates I faced some issues too.
d
Yeah they are an experimental feature of course
I think you know the project I'm using them on
👍 1
k
Right, I can confirm they deserve that status.
d
I wonder what it does when comparing unsigned ints now 🤔
k
What use case do you have for them? I have trouble coming up with anything other than unsigned ints and packed coordinates.
d
References to memory from another process
k
That's neat.
d
I've been working on replacing the inline class system over the last few days 😕
It was definitely great to start with but hasn't scaled too well
it's great though for defining remote memory structures like this
k
The memory reference system? Or do you have some general inline class stuff?
d
the prior
can confirm it doesn't box UInt when comparing two
👍 1
k
Then maybe
a >= b && a <= b
is faster.
The JVM might even realize what's going on an optimize that, but I'm not so sure.
d
p >= nullptr && nullptr <= p
😂
k
That's even easier to optimize!
d
There were millions and millions of boxed inline class instances in memory snapshots because of that comparison
k
Really? I've been led to believe the JVM was good at optimizing short lived instances too, idls there an actual performance impact?
d
if you go higher than 15 million you will definitely feel it
I can't give you numbers but I can say that the application lagged
I think I read somewhere that the GC will freeze the application if things get out of hand or something
k
This was the document I was talking about earlier, unfortunately it doesn't really say anything about the primitive mapping: https://github.com/JetBrains/kotlin/blob/master/spec-docs/NameResolution.adoc
d
Interesting read!