Hey there,
I have the following code:
int[] x = new int[7];
System.out.println(x.lengnth);
x.length = 10;
System.out.println(x.length);
Of course, line three causes a "cannot assign a value to final variable length". However, line one does assign seven to that variable, length.
Now, I have written a Testing class where I have declared a final variable of type String. I tried changing it either via the constructor or via a setter method and they both failed.
Now, my question is: how is length being set when neither a constructor nor a setter method can do this?
Another question would be:
In the Spring framework, when doing dependency injection, even if a variable is private and there is no corresponding setter method, the variable will be changed upon initialization. How is that happening?
Thank you!