String interpolation

Arne Juul arnej at yahoo-inc.com
Mon May 16 05:22:30 UTC 2011


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