< prev index next >
src/java.base/share/classes/java/lang/String.java
Print this page
*** 40,49 ****
--- 40,50 ----
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import java.util.stream.IntStream;
import java.util.stream.StreamSupport;
import jdk.internal.HotSpotIntrinsicCandidate;
+ import jdk.internal.vm.annotation.Stable;
/**
* The {@code String} class represents character strings. All
* string literals in Java programs, such as {@code "abc"}, are
* implemented as instances of this class.
*** 117,136 ****
*/
public final class String
implements java.io.Serializable, Comparable<String>, CharSequence {
! /** The value is used for character storage. */
private final byte[] value;
/**
* The identifier of the encoding used to encode the bytes in
* {@code value}. The supported values in this implementation are
*
* LATIN1
* UTF16
*
*/
private final byte coder;
/** Cache the hash code for the string */
private int hash; // Default to 0
--- 118,151 ----
*/
public final class String
implements java.io.Serializable, Comparable<String>, CharSequence {
! /**
! * The value is used for character storage.
! *
! * @implNote This field is trusted by the VM, and is a subject to
! * constant folding if String instance is constant. Overwriting this
! * field after construction will cause problems.
! *
! * Additionally, it is marked with {@link Stable} to trust the contents
! * of the array. No other facility in JDK provides this functionality (yet).
! * {@link Stable} is safe here, because value is never null.
! */
! @Stable
private final byte[] value;
/**
* The identifier of the encoding used to encode the bytes in
* {@code value}. The supported values in this implementation are
*
* LATIN1
* UTF16
*
+ * @implNote This field is trusted by the VM, and is a subject to
+ * constant folding if String instance is constant. Overwriting this
+ * field after construction will cause problems.
*/
private final byte coder;
/** Cache the hash code for the string */
private int hash; // Default to 0
< prev index next >