1

The below code compiles in Java.

public class App{
  public static void main(String args[]){   
    final int[]array = {1,2,3};
    array[2] = 6; //Why can this value be changed if it is final.
  }
}             

Why when making an array of ints "final", does it not make the values case constant. The array values can still be changed above as seen "array[2]=6".

What is the point of the keyword final being used on an array of ints? Is there any way to make this array of ints case constant.

Jeremy Levett
  • 939
  • 9
  • 13

1 Answers1

1

No. final means your reference is final, not the value.

Luis Muñiz
  • 4,649
  • 1
  • 27
  • 43