以下是伪代码
public void testImportInContext() {
ParserContext ctx = new ParserContext();
ctx.addImport("List", List.class);
ctx.addImport("ArrayList", ArrayList.class);
MVEL.eval("List test = null;User u =null", ctx);
}
发生异常
- [Error: could not access: List; in class: org.mvel2.ParserContext]
- [Near : {... List test = null;User u =null ....}]
答案 0 :(得分:0)
因为您只能在编译器中使用此功能。 eval()解释器不支持静态类型分析。 eval的第二个参数用于评估上下文对象。不是ParserContext。