【发布时间】:2016-10-23 11:15:38
【问题描述】:
对于以下代码 sn-p,我收到错误“参数类型不匹配”。 如果我使用注释行,它工作正常。
有人可以解释这种行为的原因吗?
有没有办法让我自己评估第一个表达式?
VariableResolverFactory functionFactory = new MapVariableResolverFactory();
Object value = MVEL.eval("def StringValueWithLength(str) { int myLen = str.toString().length(); return String.valueOf(str) + \":\" + myLen; }; StringValueWithLength(\"qwert\");", functionFactory);
//Object value = MVEL.eval("def StringValueWithLength(str) { return String.valueOf(str) + \":\" + str.toString().length(); }; StringValueWithLength(\"qwert\");", functionFactory);
System.out.println("Value : " + value);
【问题讨论】:
-
最新版本的 mvel 出现编译错误,您使用的是哪个版本?
MapVariableResolverFactory需要Map参数 -
JDK 1.8 和 mvel2-2.3.1.Final.
标签: java function evaluation mvel