When a variable is decorated with the final keyword in Java, is the reference immutable or does the referenced object not change?
The address value of the reference object cannot be changed, and the contents of the object that the reference variable points to can be changed.
The final variable always points to this object, which is a constant pointer, not a pointer to a constant.
For example: Final stringbuffer SBU = new StringBuffer ("abc");
Re-assigning it to a value
SBU = new StringBuffer ("");
A compilation error will occur, and the final modified variable cannot be re-assigned.
Sbu.append ("D");
Can be compiled and passed;
Final: Finally. As a modifier
1, you can modify classes, variables, functions.
2. A class that is final modified cannot be inherited. In order to avoid being inherited, quilt-like replication function.
3, the final modification of the method can not be replicated.
4. The final modified variable is a constant that can be assigned only once, either to modify the member variable or to modify the local variable.
When describing things, the value of some data is fixed, then in order to enhance the reading, all of these values are given a name, which is easy to read.
This value does not need to be changed, so with the final modifier, as a constant: The writing specification for constants all letters are capitalized, and if made up of multiple words, the words are connected through _.
5. When the inner class is defined in a local position in a class, only the local variable that is partially final decorated is accessible.
When a variable is decorated with the final keyword in Java, is the reference immutable or does the referenced object not change?