【发布时间】:2011-08-19 21:18:05
【问题描述】:
当我这样写时:
public class test {
void mainx()
{
int fyeah[] = {2, 3, 4};
smth(fyeah);
System.out.println("x"+fyeah[0]);
}
void smth(int[] fyeah)
{
fyeah[0] = 22;
}
}
它打印 x22;
当我这样写时:
public class test {
void mainx()
{
int fyeah = 5;
smth(fyeah);
System.out.println("x"+fyeah);
}
void smth(int fyeah)
{
fyeah = 22;
}
}
它不打印 x22,而是打印 x5。
为什么在第二个版本函数中,值没有变化?它是否仅更改数组元素的值?
【问题讨论】:
-
你的意思可能是
int[] fyeah = {2,3,4}。 -
@zneak 我认为它们都有效。你的方式比较常见,它们都应该编译。