question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ImmutableMap.ofEntries()

See original GitHub issue

Currently, Immutable.of() supports only up to 5 key-value pairs. I suggest adding a new method ImmutableMap.ofEntries(Entry<K, V>...) similar to Map.ofEntries() that appeared in Java 9. This will allow creating ImmutableMap with any number of key-value pairs.

I also suggest making ImmutableMap.entryOf(K, V) public so it can be used in ofEntries():

ImmutableMap.ofEntries(
    ImmutableMap.entryOf("a", 1),
    ImmutableMap.entryOf("b", 2));

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
orionllcommented, Sep 25, 2021

ImmutableMap.ofEntries() has been added in https://github.com/google/guava/commit/cd3b4197fb523bf26f9122492915006ad306b3f3. It’s now available since Guava 31.

0reactions
orionllcommented, Feb 21, 2020

… and constructing Entry objects that will immediately be discarded

In ImmutableMap.Builder.put() and ImmutableMap.of() there are also temporary Entry objects that are discarded.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - What is the use of Map.ofEntries() instead of Map.of()
Returns an immutable Map.Entry containing the given key and value. These entries are suitable for populating Map instances using the Map.
Read more >
Java 9 Map.ofEntries() Method - Create Immutable Map ...
In this post, I show you how to create an immutable Map using Java 9 provided Map.ofEntries() static factory method. Create Immutable Map....
Read more >
ImmutableMap (Guava: Google Core Libraries for Java 31.1 ...
Returns a new builder, expecting the specified number of entries to be added. void, clear(). Deprecated. Unsupported operation. V ...
Read more >
Immutable Map Implementations in Java - Baeldung
Finally, we can use ImmutableMap.of() method to create an immutable map with a set of entries provided on the fly.
Read more >
Java Map.of() and Map.ofEntries() Example - ConcretePage.com
ofEntries are the static factory methods of java.util. ... ofEntries() Example ... The unmodifiable Map and immutable Map are not same.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found