我已经在我们的Maven Java项目pom.xml中添加了Manifold.systems Java库:
<dependency>
<groupId>systems.manifold</groupId>
<artifactId>manifold-ext</artifactId>
<version>${manifold-version}</version>
</dependency>在此之后,将编译以下代码行:
String foo = "$HIS";编译失败:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /c:/workspaces/dev/src/main/java/com/foo/bar/MyClass.java:[26,24] cannot find symbol
symbol: variable HIS
location: class com.foo.bar.MyClass
[INFO] 1 error显然,这是Manifold String模板试图找到一个名为$HIS的变量,该变量没有在作用域中定义。因此,我需要转义$符号,因为我需要它成为字符串文字的一部分。我该怎么做呢?如果我使用\$,那么IntelliJ会尖叫“字符串文字中的非法转义字符”。
发布于 2021-10-01 12:56:24
我发现最优雅的方式是使用同一个Manifold库中的注解@DisableStringLiteralTemplates:
import manifold.rt.api.DisableStringLiteralTemplates;
public class FooExample {
@DisableStringLiteralTemplates
public void sampleMethod() {
String foo = "$HIS";
System.out.println("Foo is " + foo);
}
}用\$转义美元也是有效的,只需要IntelliJ Manifold.systems插件就可以识别Manifold Java库的所有函数。
有关流形字符串模板的详细说明可在此处找到:https://github.com/manifold-systems/manifold/tree/master/manifold-deps-parent/manifold-strings
https://stackoverflow.com/questions/69388699
复制相似问题