2013-10-25 2 views
0

저는 mypackage 패키지에 수학 수업을 가지고 있습니다. 이제 MVEL에서이 클래스를 가져 와서 속성에 값을 할당하고 메서드에 액세스하려고합니다.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); 

답변

0

는 아래의 접근 방식을 시도하십시오 같이 다음 코드 있지만주는 오류를 작성했습니다.

public static void main(String[] args) { 

     Map map = new HashMap(); 
     MyMaths mayMaths = new MyMaths(); 
     map.put("obj", mayMaths); 

     String expression1 = "obj.a = 20"; 

     Serializable compiled1 = MVEL.compileExpression(expression1); 

     MVEL.executeExpression(compiled1, map); 

     System.out.println(mayMaths.getA()); 
    } 

출력 - 20

관련 문제