我想按顺序解析MVEL:
HashMap myData = new HashMap(){{ put("x", 1); }}
eval("y = 2", ...) // assign value to y
...
eval("x + y", myData, ...) // expect 3
这可能吗?如果是这样,怎么样?
答案 0 :(得分:2)
只需在表达式评估中共享变量解析器:
VariableResolverFactory vars = new MapVariableResolverFactory(new HashMap(){{put(“x”,1);}});
MVEL.eval(“y = 2”,vars): MVEL.eval(“x + y”,vars);