Re: Dymanic if statement evaluation problem with string comparison
David <[email protected]> Sat, 15 May 2010 08:26:48 -0400
| Newsgroups | gmane.comp.java.beanshell.user |
|---|---|
| Message-ID | <[email protected]> |
the core issue here is that == doesnt do what you think it does, in bsh
or in java.
== compares 2 objects for identity , not the contents of 2 objects.
its possible for 2 objects to have the same value but not be the same object
Hence you should use equals()
http://www.xmlsh.org
On 5/14/2010 11:47 PM, Manikandan R wrote:
> Hi Everyone,
>
> I am able to do the string comparison using eval function with string
> methods something like string.equals("test"), but not able to do something
> like string == "test".
>
> Here is the code which works fine - getting the success as output:
>
> String s = "test";
>
> String cond = "s.equals(\"test\")";
>
> Interpreter i = new Interpreter();
>
> i.set("s", s);
> if((Boolean)i.eval(cond)) {
> System.out.println("success");
> } else {
> System.out.println("fail");
> }
>
> Can anyone help me onhow to achieve the same using without string equals
> method?
> Thanks,
> Mani
> ------------------------------------------------------------------------------
>
> _______________________________________________
> Beanshell-users mailing list
> Beanshell-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/beanshell-users
>
------------------------------------------------------------------------------