java.lang.StringTemplate.RAW is not implicitly imported?

Jim Laskey james.laskey at oracle.com
Tue Nov 14 13:38:59 UTC 2023


Thank you for pointing that out. We will revise.

On Nov 13, 2023, at 5:03 PM, Ella Ananeva <ella.ananeva at oracle.com> wrote:

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; andimport 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/20231114/3f689c0e/attachment.htm>


More information about the amber-dev mailing list