首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

能帮小弟我看看小弟我理解的对吗 有关String

2012-04-19 
能帮我看看我理解的对吗 有关StringHeap and stack in JavaWhen you create an object using the new oper

能帮我看看我理解的对吗 有关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有点不准确

热点排行