Tag: 评估策略

数组在方法中有变化吗?

我写这样的时候: 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。 为什么在第二个版本函数中,值没有变化? 它是否只更改数组元素的值?