One of the hottest new features in Java 9 are so-called compact strings , which have been created to adopt a more spacious internal representation for strings , as explained in the JEP .
There is also talk of a new ClassString
, and compact strings will affect string-related classes like AbstractStringBuilder
, , StringBuilder
and StringBuffer
.
This is the description of JEP 254 (the link is the same as above):
We propose to change the internal representation of the String class from a character
UTF-16
array to a byte array plus an encoding-flag field. The new classString
will store characters encoded asISO-8859-1 / Latin-1
(one byte per character), or asUTF-16
(two bytes per character), based on the content of the string. The encoding indicator will indicate which encoding is used.String-related classes like
AbstractStringBuilder
, ,StringBuilder
andStringBuffer
will be updated to use the same representation, as will the HotSpot VM's intrinsic string operations.This is purely an implementation change, with no changes to existing public interfaces. There are no plans to add new public APIs or other interfaces.
The last paragraph of this text is not clear to me and so I wonder to what extent the compact chains will affect our applications already created or the applications we create from Java 9.
In nothing! Well, hopefully they might consume a little less memory.
This is an internal change to OpenJDK of an implementation detail, the Java standard does not change at all.
From the website, objectives of the change:
No behavior change, just make them consume less memory space.
From the testing section:
Or what is the same, make sure that the change does not affect the behavior of the classes beyond the memory improvement.