我在一个包中有一个数学课mypackage
。现在我想在 MVEL 中导入这个类并将值分配给它的属性并访问它的方法。我已经编写了以下代码,但它给出的错误为
Exception in thread "main" [Error: unknown class or illegal statement:
^
代码是
ParserContext context = new ParserContext();
context.addImport("math",mypackage.MyMaths.class);//MyMaths.class is public
context.addInput("obj", mypackage.MyMaths.class);
String expression1 = "obj.a == 20";//a is public property
Serializable compiled1 = MVEL.compileExpression(expression1,context);
MVEL.executeExpression(compiled1);