日期:2014-05-20  浏览次数:20702 次

能帮我看看我理解的对吗 有关String
Heap and stack in Java
When you create an object using the new operator, for example myobj = new Object();, it allocates memory for the myobj object on the heap. The stack memory space is used when you declare automatic variables.

Note, when you do a string initialization, for example String myString;, it is a reference to an object so it will be created using new and hence it will be placed on the heap.
来源:http://www.maxi-pedia.com/what+is+heap+and+stack

他的意思 是不是说 你声明一个String变量 就有了堆区空间? 但堆里面的东西不是一般new出来的(一般)
但有点...... when you do a string initialization,是说你初始化一个String对象
但是后面给的例子....不是声明吗? for example String myString; 他是不是前后矛盾了?....
.....我混沌了............是原文错了吗? 还是........我理解的问题 望解答 

谢谢

------解决方案--------------------
探讨
Note, when you do a string initialization, for example String myString;, it is a reference to an object so it will be created using new and hence it will be placed on the heap.

------解决方案--------------------
Note, when you do a string initialization, for example String myString;, it is a reference to an object so it will be created using new and hence it will be placed on the heap.
已经初始化了这个引用,如:
1、String str = new String("ABC"); //"ABC"被放在了heap上;
2、String str = "ABC"; // 假设第一次使用"ABC"这个字符串,"ABC"被放在常量池,这里说heap有点不准确