Java中说引用传递-这是不准确的
来源:互联网 发布:查看ubuntu详细版本 编辑:程序博客网 时间:2024/05/17 10:25
参考文章:http://www.javaranch.com/campfire/StoryPassBy.jsp
看如下代码:
package test;public class TestReference {int a,b;TestReference(int a,int b){this.a = a ;this.b = b;}static void doTest(TestReference tr){tr = new TestReference(6, 7);System.out.println("doTest中a = "+tr.a);}public static void main(String[] args) {TestReference t = new TestReference(2,3);System.out.println("t修改前a="+t.a);doTest(t);System.out.println("t修改后a="+t.a);}}
运行结果:
t修改前a=2
doTest中a = 6
t修改后a=2
总结:java中只有值传递(pass by value),引用上面英文文章中的原话:
Java is pass-by-value.
For primitives, you pass a copy of the actual value.
For references to objects, you pass a copy of the reference (the remote control).
You never pass the object. All objects are stored on the heap. Always.
Now go have an extra big cup of coffee and write some code.
- Java中说引用传递-这是不准确的
- Java中, 不存在引用传递(也就是地址传递)一说, 全部都是值传递
- Java中引用传递
- Java中字符串的“引用”传递
- java中引用数据类型的传递
- JAVA中引用数据类型的参数传递
- JAVA中方法参数的引用传递
- JAVA中方法参数的引用传递
- Java的引用传递
- java的引用传递
- java的引用传递
- java的引用传递
- java 引用的传递
- java中没有引用传递
- Java中不存在引用传递?
- java中没有引用传递!
- Java:理解Java中函数参数传递的【按值传递】和【按引用传递】
- Java中对象、对象引用、堆、栈、值传递以及引用传递的详细解释
- 项目 - 智能交通(1)
- mysql的备份和还原
- 使用命令行编译VC++程序
- display常用属性及inline元素之间的空白和padding的问题
- 基友记
- Java中说引用传递-这是不准确的
- 1815[Distance]
- mysql加密函数
- Hibernate的检索方式(一)
- test
- Oracle - SGA → Data_buffer_cache 之 Keep pool
- C++单例模式与线程安全
- 10491 - Cows and Cars (概率)
- 博客第一天,以后会多多交流的!