Why do primitive versions of interfaces do not implement java.util interfaces ?
pylvain opened this issue Β· comments
Why for example, LongLongMap
do not implements Map<Long,Long>
?
It does make it harder to plug primitive versions in existing code.
I'm not saying that is wrong, I'm just curious about the design choice behind.
Thank you π
Implementing Map<Long,Long>
would require constant wrapping/unwrapping. Eclipse collections targets scenarios that are garbage and memory sensitive. Constant wrapping/unwrapping can in some situations be even worse than just using fat Long
objects.
Said differently, from the perspective of memory/garbage, if the code around this collection is using Longs, that's a serious code smell and we don't want to perpetuate that.
Additionally, Long
can be null, which would require even more weird handling.
Handling memory/garbage with care is not a matter of "plugging" in a collection. It's a way of writing code that's literally more primitive.
Ok that makes absolute sense. I use Kotlin, and from this perspective, it's a little bit weird :
class LongReturner {
fun getLong(): Long = -1L
}
Here, looking at the bytecode, no boxing will occur. But :
interface Foo<T> {
fun getLong (): T
}
class LongReturner: Foo<Long> {
override fun getLong(): Long = -1L
}
Here boxing occur now.
Thank you for your quick replies anyway π