String s = new String ( "a") in the end produce several objects?

A terrier commonplace, to 2020 and still controversial, you day by day, Ai Aiai, I'm not against you one, I mean all of you are qualified!
Here Insert Picture Description
The figure of three red arrows, for by newthe time produces a string ( "Yichun"), will go to find the constant pool if we have the "Yichun" objects, if not then create a string in a constant pool object, and then re-create this heap "Yichun" copy target object is a constant pool.

That correct answer is the creation of one or two objects , if they had no "Yichun" constant pool is two. On the contrary was one.

Yes! If the interviewer asked, the answer to one or two, but after all ... after all ...

After all, I and you are qualified, java knowledge foundation can not be so short-sighted, this question of the interviewer can not curtain call us more than a few beeps: string constant pool may be in different locations in different versions of jvm , then this is an old stems, and here, welcomed the comments section to talk about, it is estimated the interviewer will brighten a little guy thing!

Finally, if there is insufficient or is not correct, please correct me criticism, grateful! If you have questions please leave a message, the absolute first time to reply!

I welcome you to focus on the public number, there are some java learning materials and a large wave of java e-books, such as Zhou Zhiming teacher depth java virtual machine, java programming ideas, the core technology volume, Westward design patterns, java concurrent programming are real ... java Bible, do not say fast car on Tomcat, ye who go! The main thing is to explore technology, yearning technology, the pursuit of technology, said good pots Friends is coming Oh ...

Here Insert Picture Description

Published 118 original articles · won praise 4300 · Views 670,000 +

Guess you like

Origin blog.csdn.net/qq_44543508/article/details/104560346