[External] : Re: java.lang.StringTemplate.RAW is not implicitly imported?

Jim Laskey james.laskey at oracle.com
Tue Nov 14 14:33:32 UTC 2023


To clarify, the spec is being revised to drop "import static java.lang.StringTemplate.RAW;”.

On Nov 14, 2023, at 10:31 AM, Remi Forax <forax at univ-mlv.fr> wrote:

For me,
RAW does not need to be imported by default, it's uses is not that frequent, it's more like FMT than STR.

regards,
Rémi

________________________________
From: "Jim Laskey" <james.laskey at oracle.com>
To: "Ella Ananeva" <ella.ananeva at oracle.com>
Cc: "amber-dev" <amber-dev at openjdk.org>
Sent: Tuesday, November 14, 2023 2:38:59 PM
Subject: Re: java.lang.StringTemplate.RAW is not implicitly imported?
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/fa216daf/attachment.htm>


More information about the amber-dev mailing list