【发布时间】:2019-12-19 04:22:39
【问题描述】:
我对带有双 $$ 变量的 strsubstitutor 有疑问,我有以下代码:
Map<String, Object> params = new HashMap<String, Object>();
params.put("hello", "hello");
String templateString = "The ${hello} $${test}.";
StrSubstitutor sub = new StrSubstitutor(params);
String resolvedString = sub.replace(templateString);
System.out.println(resolvedString);
输出为hello ${test}
如果test变量是双$,并且不能被替换,为什么输出是${test}?应该还是$${test}吧?
【问题讨论】:
-
$$是一个转义的$,所以它先用{test}代替它。 -
对不起,你能解释一下吗