Those who have used python should know that multiple lines of strings can be defined in python, which can be written like this:

Looks great, other languages ​​like javascript have similarities:

However, our own java has no such syntax! So in Java you can only write "multi-line" strings like this:

Look at how much… very silly feeling! (a bunch of newline and +)

Can it really only compromise this way? Do not!

Please see the implementation below:

![](/wp-content/uploads/2018/09/java multi-line string demo.gif)

Online code demo address:

Yes, you are not mistaken, it is indeed a "multi-line string" function implemented in java multi-line comments, this is a trick (small trick, not compiler level implementation), but it is very practical!

Imagine if your sql can be written like this:

Think again, you can write shell commands directly like this:

Everything is too cool, there are wood!

You can experience more features at this site: [] (

Secret moment!

So how is this small trick implemented? Directly attach the source code of the S function in the above example:

Explain that you will notice that the first line of the function has such a line of code:

That’s right, here is the source code for the class in which the S function is called, passed through the ThreadLocal object.

At this point, is there a feeling of great understanding? ! You can go to this website to experience more features: If you have any questions or concerns, please leave a comment below the blog.

Last modified: 2019年3月29日



Write a Reply or Comment

Your email address will not be published.