JLS string concatenation clarification
Vicente-Arturo Romero-Zaldivar
vicente.romero at oracle.com
Tue Jan 28 13:00:13 PST 2014
Hi Alex,
On 27/01/14 19:29, Alex Buckley wrote:
> Hi Vicente,
>
> Generated code. Also, I realize that s+"" may generate different code
> than ""+s - please indicate if that's the case.
Yes the generated code is slightly different. But at the end javac only
indicates what should be done. A string concatenation implies the
creation of a StringBuilder with calls to it's append() method. Later
the VM should these instructions only as indications.
Vicente
>
> Alex
>
> On 1/27/2014 9:33 AM, Vicente-Arturo Romero-Zaldivar wrote:
>> Hi Alex,
>>
>> Are you interested in the generated code or in the compiler's internal
>> representation?
>>
>> Thanks,
>> Vicente
>>
>> On 22/01/14 22:14, Alex Buckley wrote:
>>> To compiler-dev and others,
>>>
>>> Since the original question asked when the JLS allows compilers to
>>> deviate from "always" creating a new String object, I would like to
>>> know more about the following case:
>>>
>>> On 1/21/2014 4:45 PM, Alex Buckley wrote:
>>>> - "Semi" constant expressions like s+"". Concatenating the empty
>>>> string
>>>> literal "" with a String expression is mentioned in
>>>> https://bugs.openjdk.java.net/browse/JDK-4036535. The expectation (per
>>>> JLS1) that a new String object is always created in this case is
>>>> misplaced (per the JDK's actual behavior). But, the JLS never
>>>> clarified
>>>> this.
>>>
>>> If compiler authors can confirm (on-list or privately) that indeed
>>> "concatenation with empty string does not create the new instance of
>>> String", then I will clarify the JLS.
>>>
>>> Alex
>>
More information about the compiler-dev
mailing list