Dymanic if statement evaluation problem with string comparison
- by Mani
I tried the example given in http://forums.sun.com/thread.jspa?threadID=780576&tstart=67605
to create if statement dynamically. But it is not working fine. Instead of using "age" variable as integer, i have used string in the below example. I am getting "fail" as answer instead of "success".
Can anyone help me?
/
To change this template, choose Tools | Templates
and open the template in the editor.
/
import java.lang.reflect.*;
import bsh.Interpreter;
public class Main {
public static String d;
public static void main(String args[])
{
try {
String age = "30";
String cond = "age==30";
Interpreter i = new Interpreter();
i.set("age", age);
System.out.println(" sss" + i.get("age"));
if((Boolean)i.eval(cond)) {
System.out.println("success");
} else {
System.out.println("fail");
}
}
catch (Throwable e) {
System.err.println(e);
}
}
}
Thanks,
Mani