-
Notifications
You must be signed in to change notification settings - Fork 903
Description
When i return a string from a java object i get a java string. I remember that in older versions of rhino this was causing trouble, so we
converted them with + "" to js strings. Now i try to figure out if + "" is still necessary to code with the returned string like it would be a
native rhino js string (currently we are using 1.8).
What i recognized is that i can now use "==" to compare them, don't know if that was always possible, but
if i call functions on them i would suspect that only java functions would work. Interestingly also js functions work on the returned
string. Could you clarify or point me to a documentation on how to handle java strings in rhino?
var pname = jpage.name(); //jpage is an Java object embedded in rhino, therefore it returns a java.lang.String
pl ("|pname|" + pname); //RhinoStringTest
pl("|cname()|" + cname(pname)); //java.lang.String (cname is helper function that gets class name, if obj is a java obj)
pl("|typeof|" + typeof pname); //object
Comparing (assume pname is "RhinoStringTest")
if (pname == "RinoStringTest") //matches...
if (pname === "RinoStringTest") //does not match: java.lang.String vs object
Calling functions
pl("|split()|" + pname.split(".")); //should work since java has a split function, as has js
pl("|slice()|" + pname.slice(0,2)); //should NOT work since java string does NOT hava a splice function, but it WORKS??????
So the last line is actually causing the confusion. What is happening here. Is the object internally converted to a js object? If so,
should then === also work? It would be inconsintant if the one works, the other not.