首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JEXL程序有";“异常

JEXL程序有";“异常
EN

Stack Overflow用户
提问于 2010-07-09 10:35:42
回答 1查看 1.2K关注 0票数 0

我正在为JEXL做rnd,但我在下面的程序中得到了异常;

代码语言:javascript
复制
        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引起,表达式之间缺少';‘

有人能帮我显示我想要的输出(布尔值)吗?

提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-07-09 12:37:41

这就是了:

代码语言:javascript
复制
  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似乎不支持该语句。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3209439

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档