Enter your E-mail Address below for Free E-mail Alerts right Into your Inbox: -

Sunday

Final Arrays in java

Final Arrays in java

Normally in java a FINAL variables can't be changed. But array values can be changed. In java Array is a object.

public final class Test {


void comparaeAll()
{
 String[] a2 = {"sdafs"};
final String[] a1 = { "dsfasd", "sdfsd" };
a1 = a2; // Error, you can't do that. a1 is final
a1[0] = "over";  //good final has nothing to do with it
}

}

Thus FINAL array is not immuable

No comments:

Post a Comment