LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 960|回复: 5

Java基礎問題﹐求教﹐謝謝。

[复制链接]
自由狼-台风 该用户已被删除
发表于 2005-7-13 18:01:47 | 显示全部楼层 |阅读模式
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2005-7-14 08:27:06 | 显示全部楼层
String 是不可改变的

变量 只是 到 对象的一个引用
回复 支持 反对

使用道具 举报

自由狼-台风 该用户已被删除
 楼主| 发表于 2005-7-14 08:47:57 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复 支持 反对

使用道具 举报

发表于 2005-7-14 10:35:21 | 显示全部楼层
使用new後送回的是一個地址,但聲明的變量不是

比如

  1. JButton button1;
  2. JButton button2;
  3. button1=new JButton();
  4. button2=button1;
复制代码


button2.setText("something") 之後

button1.getText值也是"something"
回复 支持 反对

使用道具 举报

发表于 2005-7-26 10:51:34 | 显示全部楼层
String的赋值方式比较特殊,以下文字选自《The JavaTM Tutorial》:

Because the compiler automatically creates a new string object for every literal string it encounters, you can use a literal string to initialize a string:
String s = "Hola Mundo";

The preceding construct is equivalent to, but more efficient than, this one, which ends up creating two identical strings:
String s = new String("Hola Mundo"); //don't do this

可见语句str_1="111";编译器其实上将它翻译成str_1=new String("111");
回复 支持 反对

使用道具 举报

发表于 2005-7-26 21:49:44 | 显示全部楼层
String是值拷贝的(和基本数据类型一样),其他对象是共享引用的
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表