0

我想按如下顺序解析 MVEL:

HashMap myData = new HashMap(){{ put("x", 1); }}

eval("y = 2", ...) // assign value to y
...
eval("x + y", myData, ...) // expect 3

这可能吗?如果是这样,怎么做?

4

1 回答 1

2

只需在表达式评估之间共享变量解析器:

VariableResolverFactory vars = new MapVariableResolverFactory(new HashMap(){{ put("x", 1); }});

MVEL.eval("y = 2", vars): MVEL.eval("x + y", vars);

于 2012-09-01T01:15:10.130 回答