String作为函数参数时,传入的是值,不是地址
2016-04-24 16:22
387 查看
写个小程序试下:
public class Example {
String str = new String("good");
char[] ch = { 'a', 'b', 'c' };
public static void main(String args[]) {
Example ex = new Example();
ex.change(ex.str, ex.ch);
System.out.print(ex.str + " and ");
System.out.print(ex.ch);
}
public void change(String str, char ch[]) {
System.out.println("str:"+str+", ch:"+ch);
str = "test ok";
ch[0] = 'g';
}
}
运行结果:
str:good, ch:[C@de6ced
good and gbc
public class Example {
String str = new String("good");
char[] ch = { 'a', 'b', 'c' };
public static void main(String args[]) {
Example ex = new Example();
ex.change(ex.str, ex.ch);
System.out.print(ex.str + " and ");
System.out.print(ex.ch);
}
public void change(String str, char ch[]) {
System.out.println("str:"+str+", ch:"+ch);
str = "test ok";
ch[0] = 'g';
}
}
运行结果:
str:good, ch:[C@de6ced
good and gbc
相关文章推荐
- 将一个正整数分解质因数。例如:输入90,打印出90=2*3*3*5。
- Java中回调函数编写
- Windows-消息映射机制原理和简单的绘图技术
- Java中回调函数编写
- 左偏树的正确性和复杂度分析
- Android Studio 导入各种形式的三方库
- Huffman树&&Huffman编码(附完整源码)
- SIFT特征--方向赋值与关键点描述
- 文件读写函数 -- 字符串读写
- 八皇后问题,递归法
- Android ContentProvider基础
- 写论文第二天:验证交易策略
- 判断单链表是否有环的两种方法(转)
- iostat监控磁盘io
- C++new实现机制
- 求指导。。。运行停止工作的原因。
- Restricted Boltzmann Machine(to be continued)
- 广义逆矩阵
- atom折腾小记
- 崩溃日志管理工具的重要性