String 被声明为 final,因此它不可被继承。(Integer 等包装类也不能被继承)
    在 Java 8 中,String 内部使用 char 数组存储数据。

    1. public final class String
    2. implements java.io.Serializable, Comparable<String>, CharSequence {
    3. /** The value is used for character storage. */
    4. private final char value[];
    5. }

    在 Java 9 之后,String 类的实现改用 byte 数组存储字符串,同时使用 coder 来标识使用了哪种编码。

    1. public final class String
    2. implements java.io.Serializable, Comparable<String>, CharSequence {
    3. /** The value is used for character storage. */
    4. private final byte[] value;
    5. /** The identifier of the encoding used to encode the bytes in {@code value}. */
    6. private final byte coder;
    7. }

    value 数组被声明为 final,这意味着 value 数组初始化之后就不能再引用其它数组。并且 String 内部没有改变 value 数组的方法,因此可以保证 String 不可变。