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

Anatoly Kupriyanov kan.izh at gmail.com
Tue Nov 14 17:24:42 UTC 2023


Hm. Weird, it seems the class itself is imported by default. This code
compiles just fine even without any import statements at all. It does not
look right to me. But maybe I'm not using the latest version?

StringTemplate st = null;


On Tue, 14 Nov 2023 at 14:32, 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
>
>
>
>

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


More information about the amber-dev mailing list