Abbreviated string constant pool

First, the concept: a string constant pool: JVM In order to reduce duplication of string object is created, it maintains a special memory, this memory pool known as a string constant or string literal pool
Second, the principle: When the code when you create a string object literal form appears, JVM will first inspect the literal, quoted string object string constant pool if there is the same content, then this reference is returned, otherwise a new string object is created then this reference into the string constant pool, and returns the reference.
Third, to achieve premise: a prerequisite string constant pool is implemented in Java String objects are immutable, so you can ensure the safety of multiple variables to share the same object. If the String object in Java variable, then a reference to the operation of changing the value of an object, then the other variables are also affected, obviously this is unreasonable.

Guess you like

Origin www.cnblogs.com/yangrongkuan/p/12028514.html