JDK 10 源码之String类

一、成员变量

    (1@Stable//表示安全,该字段不会为null。
        private final byte[] value;//字节数组保存字符串的值2/** Cache the hash code for the string */
        private int hash; // Default to 03private final byte coder;
        说明:当字符串是静态常量时,该字段会被隐藏。

二、构造函数
    说明:因为字符串是不可变得,除非明确需要初始化,否则没必要调用这些构造方法。

    (1)空字符串,空字符串没有hash字段。
     public String() {
        this.value = "".value;
        this.coder = "".coder;
    }
    (1)指定字符串。
     public String(String original) {
        this.value = original.value;
        this.coder = original.coder;
        this.hash = original.hash;
    }

猜你喜欢

转载自blog.csdn.net/bengxu/article/details/80726501