当我将Array 项的值分配给临时变量后更改其值时,主变量值也会更改。Array<Cards> cards = new Array<Cards>();//add items to cardsIterator<Cards> iterator = cards.iterator();while(iterator.hasNext()){ Cards c = iterator.next(); Cards Temp = c; //when I change values of temp...the value of c also changes //overall changing the value of cards}有什么方法可以更改Temp的值,而不是c或card?我目前正在用libgdx开发Android游戏。 最佳答案 您需要复制c引用的对象。您当前正在做的只是简单地创建对同一对象的另一个引用。根据Card实现和您的需要,您可以执行clone或显式创建新的Card。关于java - 在Java Array <> libgdx中需要帮助,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31661635/
10-11 19:58