Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

How does the jvm know the map is immutable?

But interned strings can also reuse their hashcode forever.



Map.of() promises to return an immutable map. new HashMap<>() does not.

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/...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: