java.lang.StringTemplate.RAW is not implicitly imported?
Ella Ananeva
ella.ananeva at oracle.com
Mon Nov 13 21:03:20 UTC 2023
Hi team,
Reading the JEP 459 spec, I see this:
The static members STR and RAW declared in the predefined interface StringTemplate, as if the declarations import static java.lang.StringTemplate.STR; and import static java.lang.StringTemplate.RAW; appeared at the beginning of each compilation unit immediately after any package declaration.
As a result, the names of all implicitly imported classes, interfaces and static fields are available as simple names in every compilation unit.
So, I assume this should work:
package test;
public class Example {
public static void main(String argv[]) {
int a = 1;
StringTemplate raw = RAW."\{a}";
}
}
But I get
java:7: error: cannot find symbol
StringTemplate raw = RAW."\{a + b}";
^
symbol: variable RAW
location: class Example
java --version
java 22-internal 2024-03-19
Java(TM) SE Runtime Environment (build 22-internal-2023-11-03-1839366.james.laskey.open)
Java HotSpot(TM) 64-Bit Server VM (build 22-internal-2023-11-03-1839366.james.laskey.open, mixed mode, sharing)
This code compiles if I add a static import import static java.lang.StringTemplate.RAW;
STR is available through static import, so it’s only RAW that causes issues.
Could it be a bug in JDK?
Thank you,
Ella Ananeva
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20231113/deb6b614/attachment-0001.htm>
More information about the amber-dev
mailing list