Closed GoogleCodeExporter closed 9 years ago
Beanshell handles '==' like java and not e.g. like JavaScript. That means
you've got to use "equals" to compare instances.
bsh % "abc" == "abc";
<true>
bsh % "abc" == new String("abc");
<false>
bsh % "abc".equals("abc");
<true>
bsh % "abc".equals(new String("abc"));
<true>
Original comment by pejob...@gmail.com
on 5 Jun 2013 at 6:48
Hello Guys,
thank you for your quite fast answer and detailed answer. But to be honest, i
simply expected it, to act more loosely.
What about that:
public class BashTester {
public static void main(String[] args) throws EvalError {
Interpreter interpreter = new Interpreter();
interpreter.setStrictJava( <<<- true or false ->>> );
interpreter.set("questionA", new String("answer"));
interpreter.set("questionB", "answer");
System.out.println(interpreter.eval("questionA==\"answer\""));
System.out.println(interpreter.eval("questionB==\"answer\""));
}
}
Original comment by can.sent...@likaliner.de
on 5 Jun 2013 at 7:21
And you base your expection on what?
Original comment by pejob...@gmail.com
on 5 Jun 2013 at 9:22
1) if i use loose variable types, than there is no real difference between
foo = "test";
and
foo = new String("test");
2) the great advantage of bsh is the simple use and the unnecessary
understanding difference of objects and instances in java.
But, it is not my code and i'm not part of your group. so you have to decide
you own, if it will enhance you engine or not.
I personally like the lib and think this mode of operation is intuitively right
for the "none-strict-java" behaviour.
Original comment by can.sent...@likaliner.de
on 5 Jun 2013 at 9:52
Sorry, I don't think this can be changed. First it will break compatibility.
And 2nd I don't think changing the behaviour of "==" just for
java.lang.String-type will be understood by java developers. And 3rd: When this
is changed, you must supply compare instances for 'same instance' (e.g.
something like "===").
Original comment by pejob...@gmail.com
on 5 Jun 2013 at 10:33
ok, i already have a fork and it is now running fine for my purpose.
Thank you for your time.
Enjoy
Original comment by can.sent...@likaliner.de
on 5 Jun 2013 at 10:40
Original issue reported on code.google.com by
can.sent...@likaliner.de
on 4 Jun 2013 at 10:31