concatenation of string constants in java(java中字符串常量的连接)
问题描述
In C++, the best canonical way to create a multiline string of which I am aware is to create adjacent strings and let the compiler concatenate them at compile time, like this:
In Java, the only way I know to do this is with concatenation:
The question is, does this generate a single string at runtime, or does java actually concatenate at compile time also? The reason the question comes up is because of the following behavior:
Is same as:
So it creates a new instance of String
.
You can even try:
这篇关于java中字符串常量的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!