4 ms·
How does the jvm know the map is immutable? But interned strings can also reuse their hashcode forever.
by Traubenfuchs 1y ago
How does the jvm know the map is immutable?
But interned strings can also reuse their hashcode forever.
- amiga386 1y agoMap.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/...