Dymanic if statement evaluation problem with string comparison

Posted by Mani on Stack Overflow See other posts from Stack Overflow or by Mani
Published on 2010-05-15T03:22:41Z Indexed on 2010/05/15 3:34 UTC
Read the original article Hit count: 353

Filed under:
|
|
|
|

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

© Stack Overflow or respective owner

Related posts about bean

Related posts about shell