Where is the java String addition overload implemented?
We know that java does not allow programmers to reload any operators. How is the String addition reload implemented? You can't find any clue about addition or overloading by checking the source code of String. Find the relevant books and find the following description: The "+" and "+ =" operators used for String are the only two overloaded operators in java. It seems that there is indeed a overload, so where is the implementation of overload? Let's take a look at the following example: String s1 = "foo"; String s2 = "bar"; String s3 = s1 + s2; below we compile this code into a class file and decompile it, the decompiled code is as follows: String s = "foo"; String s1 = "bar"; String s2 = (new StringBuilder ()). append (s ). append (s1 ). toString (); we can see that the compiler has helped us with the heavy load. Although this unique addition overload increases the readability of the language, it undoubtedly increases the learning cost of the java language. How to Implement the compiler will be supplemented in the future.