我正在为JEXL做rnd,但我在下面的程序中得到了异常;
String strDuration = "4560";
long lDuration = Long.parseLong(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);异常:由: org.apache.commons.jexl2.parser.ParseException:歧义语句@1:30引起,表达式之间缺少';‘
有人能帮我显示我想要的输出(布尔值)吗?
提前谢谢。
发布于 2010-07-09 12:37:41
这就是了:
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);
}编辑:需要说明的是,问题在于您使用了return语句,JEXL似乎不支持该语句。
https://stackoverflow.com/questions/3209439
复制相似问题