MVEL Lambda和关闭在严格模式下打字

时间:2014-05-20 10:27:38

标签: lambda mvel

我尝试在严格模式下使用MVEL,但发生错误,我不明白为什么!

这是我的单一测试:

@Test
public void testMVEL(){
 String any = "def any(l, m) { for (ee : l) { if (m(ee)) return true;} return false; } \n";
    String cond = "if  (any({1,2,3,50,99} ,  def (i) {i > 100}))  true;  false;";
    ParserContext ctx = new ParserContext();
    ctx.setStrictTypeEnforcement(true);
    Serializable compiled = MVEL.compileExpression(any + cond, ctx);
    boolean res = MVEL.executeExpression(compiled,new HashMap(), Boolean.class);
    Assert.assertFalse(res);
}

错误是:

[Error: unqualified type in strict mode for: )]
[Near : {... if  (any({1,2,3,50,99} ,  def (i) {i > 100}))  true;  false; ....}]
                                                       ^
[Line: 2, Column: 44]
at org.mvel2.compiler.PropertyVerifier.getBeanProperty(PropertyVerifier.java:307)
at org.mvel2.compiler.PropertyVerifier.analyze(PropertyVerifier.java:117)
at org.mvel2.compiler.ExpressionCompiler.verify(ExpressionCompiler.java:381)
at org.mvel2.compiler.ExpressionCompiler._compile(ExpressionCompiler.java:273)
at org.mvel2.util.ParseTools.subCompileExpression(ParseTools.java:2119)
at org.mvel2.ast.IfNode.<init>(IfNode.java:58)
at org.mvel2.compiler.AbstractParser.createBlockToken(AbstractParser.java:1498)
at org.mvel2.compiler.AbstractParser._captureBlock(AbstractParser.java:1701)
at org.mvel2.compiler.AbstractParser.captureCodeBlock(AbstractParser.java:1543)
at org.mvel2.compiler.AbstractParser.nextToken(AbstractParser.java:380)
at org.mvel2.compiler.ExpressionCompiler._compile(ExpressionCompiler.java:128)
at org.mvel2.compiler.ExpressionCompiler.compile(ExpressionCompiler.java:62)
at org.mvel2.MVEL.compileExpression(MVEL.java:810)

错误?

0 个答案:

没有答案