2 ms·
Map.of() promises to return an immutable map. new HashMap<>() does not. https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Map.html#unmodif
by amiga386 2y ago
Map.of() promises to return an immutable map. new HashMap<>() does not.
https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Map.html#unmodifiable https://docs.oracle.com/en/java/javase/17/docs/api/java.base...
How it tells the JVM this? It uses the internal annotation @jdk.internal.ValueBased
https://github.com/openjdk/jdk/blob/jdk-17-ga/src/java.base/share/classes/java/util/ImmutableCollections.java#L144 https://github.com/openjdk/jdk/blob/jdk-17-ga/src/java.base/...