We know that an Array object (array) has a length
attribute and it was declared in Java as:
public final int length;
It was declared as final thus no accessor is needed and we cannot change the value of length unless a new array is created.
My question is: I am very curious how did Java implemented the array class such that they are able to assign a value to length
when it was declared as final
in the first place?
How would the implementation look like?
NOTE: I am not asking how to change an array's length. I am asking how is it implemented such that a final attribute's value could be updated.
It does not change its value, it assigns it once and never changes. Arrays are fixed length per instance and the array assigns a value to the
final
field in its constructors (as far as it is only once).