Skip to content

Commit 52840b6

Browse files
kevinoconnor7Google Java Core Libraries
authored andcommitted
J2CL: expose ImmutableMap.ofEntries to JS
Callers from JS can use `java.util.Map.entry(key, value)` to create `Entry` instances to pass to this. For example: ```js const m = new Map([["key1", "value1"], ["key2", "value2"]]); const immutableMap = ImmutableMap.ofEntries( ...m.entries().map(([k, v]) => java.util.Map.entry(k, v)) ); ``` RELNOTES=n/a PiperOrigin-RevId: 883670695
1 parent e35bf7d commit 52840b6

File tree

1 file changed

+7
-0
lines changed
  • guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect

1 file changed

+7
-0
lines changed

guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/ImmutableMap.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.function.Function;
3737
import java.util.stream.Collector;
3838
import java.util.stream.Collectors;
39+
import jsinterop.annotations.JsMethod;
3940
import org.jspecify.annotations.Nullable;
4041

4142
/**
@@ -242,6 +243,12 @@ public static <K, V> ImmutableMap<K, V> ofEntries(Entry<? extends K, ? extends V
242243
return new RegularImmutableMap<>(entries);
243244
}
244245

246+
/** ImmutableMap.ofEntries API that is friendly to use from JavaScript. */
247+
@JsMethod(name = "ofEntries")
248+
static <K, V> ImmutableMap<K, V> jsOfEntries(Entry<? extends K, ? extends V>... entries) {
249+
return new RegularImmutableMap<>(entries);
250+
}
251+
245252
public static <K, V> Builder<K, V> builder() {
246253
return new Builder<K, V>();
247254
}

0 commit comments

Comments
 (0)