Empty constructor in class String

So, I read the String class when I came across one confusing constructor. The code is as follows

public final class String
    implements java.io.Serializable, Comparable<String>, CharSequence {

    /** The value is used for character storage. */
    private final char value[];

    /** Initializes a newly created {@code String} object so that it represents
    * an empty character sequence.  Note that use of this constructor is
    * unnecessary since Strings are immutable.
    */
    public String() {
        this.value = "".value;
    }
// the rest of the class code
}

I do not understand what does

"".value;

do. What is that ""? Is it new String object? If so, with which constructor?

+4
source share
2 answers

What it is? Is this a new String object?

This is an empty string. It should not be new and, most likely, is not, since string literals are interned .

If so, with which constructor?

, , Scanner , String(char[], int, int).

ClassLoader , , java_lang_String::create_from_unicode() .

"": . interned, "".value char .

OpenJDK (7, 8), this.value = new char[0];. char new String(), (.. , ).

OpenJDK 9 "".value.

char , , , . ( ) char.

, , - new String().

+1

"" String , , char[] values, String. , values .

, values .

0

All Articles