ファビオ・モライス:
私のような何かをしたいです:
this.x=4;
this.y=5;
this.materials = [this.x, this.y];
this.materials[0]=5;//this will change the x variable
この結果は、私の元の値ということでなければなりませんx
変数が5になるはずです。
Javaでの可能な変数のような配列ですか?
flaviuratiu:
(ないまさにそのような)と同様のものがオブジェクトで可能です:
あなたはNumberクラスを持っていた場合:
class Number {
int value;
Number(int value) {
this.value = value;
}
}
そして、あなたはこのような何かを試してみました:
Number x = new Number(4);
Number y = new Number(5);
Number[] materials = {x, y};
materials[0].value = 5;
// the value property of the first number object in the array
// (same as referenced by x) became 5
それ以外の場合は、materials[0] = something
単に配列の最初の要素を置き換えます。