04/01/12 16:54
class test {
public static void main(String args[]) {
int x[] = {1,2,3,4,5};
disp(x);
change(x);
disp(x);
}
public static void change(int x[]) {
int y[] = {11,22,33,44,55};
x = y;
}
public static void disp(int x[]) {
for(int i=0; i<x.length; i++)
System.out.print(x[i] + " ");
System.out.println("");
}
}
これを動かすと
1 2 3 4 5
1 2 3 4 5
になりますが、
changeメソッドの x=y; で
yの参照をxに代入しているのでは無いのですか?
配列なので参照を変更していると思うのですが…
全然違います?
厨房レベルの質問ですいません。