eclipse / eclipse-collections

Eclipse Collections is a collections framework for Java with optimized data structures and a rich, functional and fluent API.

Home Page:http://www.eclipse.org/collections

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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 πŸ˜„