multiline: .unescape() means it's no longer a compile-time constant.

Reinier Zwitserloot reinier at zwitserloot.com
Wed Feb 28 06:07:07 UTC 2018


# .unescape() won't work if you need a compile time constant. #
A raw string has the benefit of being a compile time constant. Calling a
method on a raw string removes this property. For example, the way the
class file encodes the field between FOO and BAR in this:

Test.java> class Test {
static final String FOO = "Hello!";
static final String BAR = "Hello!".toLowerCase();
}

cmdline> javac Test.java; javap -c Test

is _wildly_ different, and it's not just for efficiency (speed/size) sake
that this is important: The annotation system, for example, requires CTCs.
Therefore, calling .unescape() on a literal means a bunch of use cases for
string literals are eliminated, leaving someone looking for a not-raw
multiline literal entirely out of luck. A way to indicate multiline and raw
separately would solve this issue.

 --Reinier Zwitserloot


More information about the amber-dev mailing list