After a blog or a little casual, as like a diary, he had just been kicked out of a big production, and ultimately chose a small company as a starting point for entering the community, and indeed skills, aspects of communicating with people are to be improved, then I will efforts, and strive to be able to go back in the future
Java source code reading program (1) String class
1.1 invariance
HashMap
The key
recommended immutable class, hematocrit String
value of this, here's immutable class refers to the color class once initialized, will not change, if modified, or it will be a new class. Next, I simply show you:
String s = "hello";
s = "world";
Very simple example, we look at the first line of s
the address
and then look at the second line of s
the address
we open rt.jar
, then open java
the bottom of the lang
package, found String
the class,
where we see two final
,
1. First is the class final
, String
not is inherited, which means that all String
the inherited methods can not be overwritten
2. Next is to save string char
array, the same is final
modified, that is to say value
the array Once initialized, its memory address can not be modified, value
permissions is private
, not external access, String
there is no way to modify the value of open, so we can assume that value
once they are assigned memory address can not be modified.
This is the String
invariance of the reason, when we want to design a class invariant time, you can mimic this style.
So most String
of the methods, must have a return value.