please refer to the code below
public class MyClass{
public static void main(
String[] args) {
int a = 0;
final int b = 1;
int[] c = { 2 };
final int[] d = { 3 };
useArgs(a, b, c, d);
System.out.println("INSIDE Main "+d[0]);
}
static void useArgs( final int a, int b, final int[] c, int[] d) {
d=c;
System.out.println("INSIDE METHOD "+d[0]);
}
}
The final int array d is passed as argument to the method useArgs().The final keyword is supposed to not let the reference point to any other object other than the array with element 3
but here inside the method d refers to another array c and compiler doesnt complain .why?
is it because the formal parameter is not final? However in the main method it still points to the original array.So does it infer arrays pass by value however I know it should pass by reference??
regs Rajesh