-
Notifications
You must be signed in to change notification settings - Fork 0
4) Using Variables and assignment Operator
pranithcodes edited this page Apr 6, 2018
·
1 revision
Variable’s that are put into Jexl Context can be used in the JexlExpression. We can also use the assignment operator, to assigne the value of a variable to other variable.
public static void main(String[] args) {
`JexlContext context = new MapContext();`
`context.set("x", 1);`
`context.set("y", 2);`
`context.set("name", "Tony");`
`context.set("firstName", "Stark");`
`JexlEngine jexl = new JexlBuilder().create();`
`JexlExpression e = jexl.createExpression("x = y ");`
`e.evaluate(context);`
`e = jexl.createExpression(" name =firstName ");`
`e.evaluate(context);`
`System.out.println("x\t::" + context.get("x"));`
`System.out.println("y\t::" + context.get("y"));`
`System.out.println("name\t::" + context.get("name"));`
`System.out.println("name\t::" + context.get("firstName"));`
}
In the above program, we have set the value’s of x, y, name, firstName to 1, 2, Tony, Stark.
When Jexl evalute the expression “x = y” and “name = firstName” , then the value of y and firstname are assigned to x and name respecitvely.
Output:
x ::2
y ::2
name ::start
name ::start