在java中使用字符串构造函数时,如何创建两个对象

在java中使用字符串构造函数时,如何创建两个对象,java,Java,我读的是SCJP凯西·塞拉的这本书(问题来源于这本书),我引用的是那本书第432页 创建新字符串 Earlier we promised to talk more about the subtle differences between the various methods of creating a String. Let's look at a couple of examples of how a String might be created, and let's f

我读的是SCJP凯西·塞拉的这本书(问题来源于这本书),我引用的是那本书第432页

创建新字符串

 Earlier we promised to talk more about the subtle differences between the various
    methods of creating a String. Let's look at a couple of examples of how a String
    might be created, and let's further assume that no other String objects exist in the
    pool:
    String s = "abc"; // creates one String object and one
    // reference variable
    In this simple case, "abc" will go in the pool and s will refer to it.
    String s = new String("abc"); // creates two objects,                   Line X
    // and one reference variable
    In this case, because we used the new keyword, Java will create a new String object
    in normal (nonpool) memory, and s will refer to it. In addition, the literal "abc" will
    be placed in the pool.
为什么它在第X行(注释中)中说它创建了两个对象

String s = new String("asdf"); 

而且
“asdf”
没有在其他任何地方引用,因此它创建了两个对象。一个是perm gen区域字符串池中的
“asdf”
,另一个是正常堆中的
新字符串(“asdf”)

您是否阅读了前面的部分并很好地理解了它们?您的个人编程老师也不是这样。它创建了文字“abc”(虽然不是真正的对象…),然后使用该文本创建一个字符串对象。“我认为把它称为两个对象的创建有点让人困惑。”雷南,那么它是什么呢。如果你知道你可以回答其他问题,请让开……不要专横here@MarounMaroun是的,我很了解前面的部分,只是我想确认是否创建了两个对象,但我知道对象仍保留在堆上,字符串池只引用这些对象。