Subj : Re: Problem using rhino under java To : webdel From : Igor Bukanov Date : Tue May 04 2004 12:40 pm Danilo wrote: > Hi, > I have this problem: > > JAVA: > > class one{ > > public Integer ret(){ > return new Integer(12); > } > } > > > Context cx = Context.enter(); > try { > Scriptable scope = cx.initStandardObjects(); > one o = new one(); > Scriptable jsarg = Context.toObject(o,scope); > scope.put("o",scope,jsarg); > s= > try { > Object result = cx.evaluateString(scope, s, "", 1, null); > }catch (JavaScriptException ex) { > > } catch (Exception ee){ > > } > } catch (Exception ee){ > > } finally { > cx.exit(); > } > > > > > JAVASCRIPT > > var x=3 > x= x + o.ret() > getWrapFactory() > > the problem is that x value is "312" instead of 15. > why interpreted o.ret() as String instead of Integer? If you change "one" into class one{ public int ret(){ return 12; } } then it should work as expected. The problem is that by default in Rhino a Java object is always represented by a special wrapper even if the object is a "boxed" primitive type. When such wrapper is present on any side of "+", it forces string context for "+" that gives "312" in your example. You can disable this wrapping of boxed values if you change Context cx = Context.enter(); try { .... into Context cx = Context.enter(); try { cx.getWrapFactory().setJavaPrimitiveWrap(false); .... Regards, Igor .