Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Kotlin optimization #339

Open
MukjepScarlet opened this issue Dec 5, 2024 · 5 comments
Open

Feature request: Kotlin optimization #339

MukjepScarlet opened this issue Dec 5, 2024 · 5 comments

Comments

@MukjepScarlet
Copy link

  1. Some APIs will conflict in Kotlin.
    Example:
Long2ObjectMap.computeIfAbsent(long, V) <-> Long2ObjectMap.computeIfAbsent(java.lang.Long, V)
  1. Kotlin built-in extensions will make many classes degenerate to normal type.
    Example:

Object2LongMap.forEach will produce entry with type java.lang.Object and java.lang.Long. And Map.put(K, V), etc.

Entry<K,V>.component1 / component2

One of the resolutions: PairExtensions.kt
I hope these stuffs could be library built-in ones, so Kotlin will give priority to existing member methods rather than extension functions

@vigna
Copy link
Owner

vigna commented Dec 5, 2024

Well, I don't understand exactly what you're asking for here—note that I'm aware of Kotlin, but I have zero knowledge of the language...

@MukjepScarlet
Copy link
Author

Well, I mean when you use this library in a Kotlin project, some frustrating conflicts will make the code more complicated.
In Kotlin we iterate a map like:

myMap.forEach { (key, value) ->
    ...something
} // key has type K and value has type V (Map.Entry<K,V>)

(componentN allow us to use destructuring expressions like var (key, value) = entry)

If myMap is an Int2ObjectOpenHashMap, and we don't want to let the key become an Integer, we have to:

myMap.int2ObjectEntrySet().forEach { entry ->
    val key = entry.intKey
    val value = entry.value
    ...something
}

So I hope the library can have built-in component1 and component2 functions for entries and pairs

@incaseoftrouble
Copy link
Collaborator

So to add that you would need public functions key_type component1() and value_type component2() on the Map.Entry?

@MukjepScarlet
Copy link
Author

Yeah, but type-specified ones, like the int intValue() and maybe @Deprecated Integer value()

@incaseoftrouble
Copy link
Collaborator

incaseoftrouble commented Dec 9, 2024

Hmmm well that would pollute the autocompletion for all Java users. I think the better solution would be to provide a primitive variant of forEach (using appropriate BiConsumers). Something like forEachPrimitive(IntDoubleBiConsumer action) etc.

Not sure about your first point though, how they are conflicting ... these "conflicts" also exist in java, there they get resolved by type information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants