java - Dynamic if statement evaluation problem with string comparison -


I have given the example that if i but it is not working properly, use the "age" variable as an integer Instead, I've used the string in the example below. I am "unsuccessful" as the answer to "success".

Can anyone help me?

  / * To change this template, select the device. Open templates in templates and editors. * / Import java.lang.reflect. *; Import bsh.Interpreter; Public class main {public stable string d; Public static zero major (string algos []) {try {string era = "30"; String cad = "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"); } And {System.out.println ("unsuccessful"); }} Hold (Throbable E) {System.err.println (e); }}}  

thanks, money

You must choose or So compare the numerical comparison or string. For this, it is necessary to use the relevant situation and type of age.

Numeric:

  int age = 30; String cad = "age == 30";  

string:

  string ages = "30"; String CAD = "Age. Angle (\" 30 \ ")";  

Comments