I am doing rnd for JEXL but i got exception for the below program;
String strDuration = "4560";
long lDuration = Long.pa开发者_C百科rseLong(strDuration);
String theExpression = "" +
"if(lDuration > 500)" +
" return true;" +
"else" +
" return false;";
Expression e = jexl.createExpression( theExpression );
JexlContext context = new MapContext();
context.set("lDuration", lDuration);
Boolean result =(Boolean) e.evaluate(context);
System.out.println("The answer : " + result);
Exception : Caused by: org.apache.commons.jexl2.parser.ParseException: Ambiguous statement @1:30, missing ';' between expressions
Can anyone help me to display the output that i want(the boolean)?
Thanks in advance.
Here you go:
public static void main(String[] args) {
String strDuration = "4560";
long lDuration = Long.parseLong(strDuration);
String theExpression = "(lDuration > 500) ? true : false;";
JexlEngine jexl = new JexlEngine();
Expression e = jexl.createExpression(theExpression);
JexlContext context = new MapContext();
context.set("lDuration", lDuration);
Boolean result = (Boolean) e.evaluate(context);
System.out.println("The answer : " + result);
}
Edit: To be clear the problem is your use of the return statement, it appears to not be supported by JEXL.
精彩评论