0

I want to sequentially parse MVEL as follows:

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

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

Is this possible? If so, how?

kevin cline
  • 2,608
  • 2
  • 25
  • 38

1 Answers1

2

Just share the variable resolver across expression evaluations:

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

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

Mike Brock
  • 296
  • 1
  • 3