【发布时间】:2013-04-06 18:41:19
【问题描述】:
我遇到了一个问题,很奇怪的问题。
当我更新类中的任何一个静态变量时,类中的其他静态变量也会更新,不知道为什么会这样。
请帮帮我,我什至不知道如何处理这个问题。
这条线产生了问题。
private static cSet currentSet = new cSet();
private static cSet currentPracticeSet = new cSet();
public static void setCurrentPracticeSetRange(int from, int to)
{
Log.e(currentPracticeSet.getCards().size()+" And "+currentSet.getCards().size(), to+" and "+from);
getCurrentPracticeSet().getCards().clear();
getCurrentPracticeSet().getCards().addAll(getCurrentSet().getCards().subList(from, to));
Log.e("Range",currentSet.getCards().size()+"");
}
currentSet 和 CurrentPracticeSet 是类的私有静态成员。 谢谢,
【问题讨论】:
-
这就是
static的意思。 -
这样更好,但我们仍然需要查看您的
static变量声明。 -
是的,我不知道。如果我猜我会说您在代码中的某处将
currentSet设置为currentPracticeSet(反之亦然)。如果你这样做,这两个变量现在指向同一个集合。 -
@RobertHarvey 为什么它们指向同一个集合,集合只是我定义的一个类。