String interpolation

Behrang Saeedzadeh behrangsa at gmail.com
Mon May 16 05:34:11 UTC 2011


That is concatenation, not interpolation. FYI:
http://en.wikipedia.org/wiki/String_interpolation

And it might be a matter of preference but IMO string interpolation is
more readable than concatenation.

Plus, "Hello #{p.name}" in Java translates to:

"Hello "+p.getName()

Furthermore, for the sake of clarity and readability most people will
write it like:

"Hello " + p.getName() (i.e. with blank spaces around +) which is more verbose.


Cheers,
Behrang Saeedzadeh
http://www.behrang.org



On Mon, May 16, 2011 at 3:22 PM, Arne Juul <arnej at yahoo-inc.com> wrote:
> On 2011-05-16 03:07, Behrang Saeedzadeh wrote:
>>
>> Has there been any discussions regarding adding String interpolation to
>> Java?
>
> it already exists.
>
>> Person p = ...;
>> String hello = "Hello #{p.name}";
>
>  String hello = "Hello "+p.name;
>
> it's about the same amount to type for all the cases:
>
>> String hello = "Hello #{p.name}, how do you do";
>  String hello = "Hello "+p.name+", how do you do";
>
>> String hello = "#{p.name}";
>  String hello = ""+p.name;
>
>> String hello = "#{p.name} is here";
>  String hello = ""+p.name+" is here";
>
> I'm programming both ruby and java, and for all practical
> purposes these two seemingly very different mechanisms
> works in exactly the same way.
>
>  -  Arne H. J.
>
>



More information about the discuss mailing list