1

I understand that the string constant pool is essentially a ConcurrentHashMap. JVM uses the FlyWeight Design Pattern to save some memory. The JVM will lookup the pool(ConcurrentHashMap) and return the reference of the old object else it will create new.

Consider creating a string literal

String literal = "Hello Java!"

JVM will not create "Hello Java!" object. It will first lookup the pool. My question is

How will the JVM do this lookup since the object "Hello Java!" does not exist yet, so it can not call the hashcode method on it ?

0 Answers0