1

If I declared a class static and it's content static would this mean that the contents of the class are no longer static?

Here's what happened, I used a ViewHolder in a Custom Adapter in Android.

When my code was like this:

static class ViewHolder {
     static TextView blah;
     //more widgets
}

The ListView had repetitive data and the rows were shuffled on scroll.

However, when I did this, no duplicates were created. Basically there was just ONE instance of each list item created and the items didn't shuffle on scroll.

static class ViewHolder {
     public TextView blah;
     //more widgets
}

Now, I know that public is the default access specifer and did not have to do anything with the change. Does a double static cancel each other out? Is it like a double negative is a positive?

1
  • No. "However, when I did this:" What happened when you did that? Commented Jul 7, 2013 at 4:17

2 Answers 2

1

The static modifier on a class makes sense only if it is an inner class. A static inner class implies that an instance of inner class can exist independently without an instance of the outer class.

The static modifier on a member variable implies that there is only one copy of that variable for all instances of the enclosing class.

So, there is no effect of static modifier on the class on the static modifier on a member variable.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. That made perfect sense.
So what happened here was I created one instance of the class and the class could create only one instance of the variables and hence it failed, yes?
0

Does a double static cancel each other out?

No.

I don't understand your description of the symptoms you're observing, so I'm afraid I can't offer any further advice ;)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.