-3

i am facing a problem, very strange problem.

When i update any one static variable within a class then the other static variables in the class also got updated, don't know why this is happening.

please help me out, i don't even know what to do with this problem.

this line creating problem.

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 and CurrentPracticeSet are the private static member of class. Thanks,

Ahmad Raza
  • 2,850
  • 1
  • 21
  • 37

1 Answers1

2

Static means that the scope of a variable is bounded by the class, not the object. If you change the value in one, they're all going to change.

Read here for more info.

Community
  • 1
  • 1
  • `static` means that the variable is scoped to the class definition. It's not really an "instance," as such. – Robert Harvey Apr 06 '13 at 18:44
  • @RobertHarvey i know about static that why i am using them. but this is strange that you have 2 static variables in one class, when you change in one variable then the other variable got updated also. – Ahmad Raza Apr 06 '13 at 18:46
  • 1
    @AhmadRaza: Show us your code containing your variable declarations. My guess is you have an error in your code that is erroneously setting both variables. – Robert Harvey Apr 06 '13 at 18:46
  • @AhmadRaza: You still haven't shown us your static variables. We need to see those. – Robert Harvey Apr 06 '13 at 18:51