With the addition of a new feature in Java7, switch can accept variables of type string, which saves the complexity of writing large if ("xxx". Equals (YYY)). The sample code is exempt, just a change of data type, if you will use the original switch and in 5 minutes to make a string type of switch, it is recommended to abandon the programmer it ...
As for the internal implementation, Java does not add new content, in fact, the code is converted into this way
Switch (Xxx.hashcode ()) {case 1024x768: //Assume the original is "AAA", while "AAA" Hashcode is 1024. if ("AAA". Equals (XXX)) { //Here is the original "AAA" under the Code }case ...}
Of course, this is only a specific version of the implementation, not guaranteed in the future will always be this way.
Finally, 2 questions are left:
1. Why should the IF ("AAA". Equals (XXX)) This judgment?
2. Ask yourself if you write this code yourself, will you write this judgment in the first time?
[One knowledge point]18-java language per day-accepts string types in switch