Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8317966

Raw type not supported for a template processor in a template expression

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P4
    • None
    • 22
    • tools
    • None

    Description

      String Templates Preview Feature:

      According to the spec:

      The type, TP, of the TemplateProcessor expression must be a subtype of StringTemplate.Processor, or a compile-time error occurs. If TP is a subtype of StringTemplate.Processor<Result,Exc>, where Result and Exc are the type arguments of the parameterized type, then the type of the template expression is Result. If TP is a subtype of the raw type StringTemplate.Processor, then the type of the template expression is Object.

      But this behaviour for raw types is not preserved by the compiler. For example, the following incorrectly results in a compile-time error.

      class TemplateTest {
          public static void main(String[] args) {
              StringTemplate.Processor s = STR;
              String name = "J_Laskey";
              var x = s."Hello \{name}";
          }
      }

      $ ./build/macosx-x86_64-server-release/images/jdk/bin/javac --enable-preview --source 22 TemplateTest.java
      TemplateTest.java:18: error: processor type cannot be a raw type: Processor
             var x = s."Hello \{name}";
                     ^
      Note: TemplateTest.java uses preview features of Java SE 22.
      Note: Recompile with -Xlint:preview for details.
      1 error

      Attachments

        Issue Links

          Activity

            People

              jlaskey Jim Laskey
              gbierman Gavin Bierman
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: