JEXL程序有“;”例外

时间:2010-07-09 02:35:42

标签: java

我正在为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,缺少';'表达式之间

任何人都可以帮我显示我想要的输出(布尔值)吗?

提前致谢。

1 个答案:

答案 0 :(得分:1)

你走了:

  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似乎不支持它。