Final keyword traps, final keyword traps
I have always been dumb and thought that the final keyword is immutable. What I did not expect is that this is always true for the basic type.
However, for final objects, you can still modify the objects and member variables in the objects. The address of the current object remains unchanged.
Yesterday I also vowed and was told that I modified the object with final, Which is immutable, the value in it will not be modified (in fact, it can be modified )!!! I am ashamed to think about it. I hereby warn myself not to come to any conclusions without knowing the truth.
For basic types, such as final int x = 1, then x is "real" and immutable, that is, if x = 0, a compilation error is displayed. (There are no other objects in it .)
For non-basic types, such as final Date date = new Date (), date. setYear (2015) will not cause any compilation errors. Because the address of this object is not modified. However, if date = null is performed, a compilation error occurs because the date address of the object changes.
In plain words, it is like: Gao fushuai can have N beebot, but there is only one wife. This wife (object) remains the same, but the wife (object) what clothes are worn by other objects and what cosmetics (objects) are changed.