値は変更することができる変数の配列を作成します

ファビオ・モライス:

私のような何かをしたいです:

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単に配列の最初の要素を置き換えます。

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=338473&siteId=1