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
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
- duplicates
-
JDK-8315458 Implement JEP 463: Implicitly Declared Classes and Instance Main Method (Second Preview)
- Resolved
-
JDK-8318767 String template in lambda, reporting "processor type cannot be a raw type"
- Closed