0

I have a Constants class, that has a static final field. I found out, that I can rewrite this field.

public static final Integer[] THUMBS = {R.drawable.one, R.drawable.two};

In my code I make

mThumbIdsForAdapter = Constants.THUMBS;

And then

mThumbIdsForAdapter[position] = mThumbIdsBlue[position];

After it my Constants.THUMBS contains element mThumbIdsBlue[position]...

How is it possible?

Thank you!

  • The reference to the array is static and final while the values contained inside are not. – dbl Aug 22 '18 at 10:40
  • 1
    Only the array reference is immutable. Java does **not** support arrays where the *content* is immutable. If you want that, you have to look into using Lists, and corresponding helper methods such as Collections.unmodifiableList(someList) In other words: when you use an array type, it is always possible to change individual slots via a simply assignment. – GhostCat Aug 22 '18 at 10:41
  • Thank you! I forgot about it( – Aleksandr M. Aug 22 '18 at 10:46

0 Answers0