'Evaluating expressions in Java using JEP

I am using JEP (Java expression parser) for a requirement. When there is a expression of the following format and the variables are replaced by numerical values, everything works smooth.

For eg:

String formula = "(A || B )" ;
JEP jep = new JEP();
jep.addVariable("A", -1.0);
jep.addVariable("B", 0.0);
jep.parseExpression(formula);
Number value = jep.getValue();
System.out.println("Value: " +value);


-----------------------------

Value : 0.0

But what when the value of A and B are booleans, eg (TRUE or FALSE) this fails. Could anyone suggest how JEP supports the boolean inputs scenario?

String formula = "(A || B )" ;
JEP jep = new JEP();
jep.addVariableAsObject("A", Boolean.TRUE); 
jep.addVariableAsObject("B", Boolean.TRUE); 

jep.parseExpression(formula);
Object val = jep.getValueAsObject();
System.out.println("Value: " +val); // gives null


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source