JEP 430 String Templates, some weird scenarios feedback

Anatoly Kupriyanov kan.izh at gmail.com
Thu Jun 15 22:01:58 UTC 2023


I understand why it works like that but it still causes some confusion to
me, at least it should be somehow documented:

var val = 1;
var template = RAW."val = \{val}";
assert template.interpolate().equals("val = 1");
val = 2;
assert template.interpolate().equals("val = 1");//weird



Another thing, I could not figure out a reasonable conditional template
syntax and nesting. This looks kind of ugly and hard to read

String msg(String name, String val)
{
return STR."Today is a nice day. \{name == null ? "" : STR."Hello \{name}! "
}You have \{val} thing.";
}

assert msg(null, "this").equals("Today is a nice day. You have this thing."
);
assert msg("World", "that").equals("Today is a nice day. Hello World! You
have that thing.");

This thing would be especially important e.g. for a JSON tree templating.


-- 
WBR, Anatoly.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20230615/f4b76d2a/attachment.htm>


More information about the amber-dev mailing list