java pass by value 。do not exist pass by reference
参数传递的只有一种那就是 按值传递
这值 可以分为两种类型
一种就是源生类型 如 int float
public class Passv {
public static void main(String []args)
{
int a=9;
A test=new A();
test.set(a);
System.out.println(a);
}
}
class A
{
int set(int a)
{
return a++;
}
}
9没有变
一种就是引用类型 如类的对象
public class TestPass{
int x;
public void set(PassValue a)
{
a.x=0;
a.x++;
}
public static void main(String []args)
{
PassValue a=new PassValue();
new TestPass().set(a);
System.out..println(a.x);
}
}
源生类型的 存放 栈
引用类型 既有堆又有栈
本文详细解析Java中参数传递的机制,包括值传递和引用传递的区别,通过实例演示源生类型和引用类型的传递过程,解释栈和堆在参数传递中的作用。

被折叠的 条评论
为什么被折叠?



