Subj : Re: null to jsFunction_ with Integer parameter is 0 To : Trinition From : Igor Bukanov Date : Tue Feb 01 2005 11:36 am Trinition wrote: > I have a ScriptableObject with a function: > > jsFunction_setBgcolor(Integer color) { > .... > } > > Originally, this function took an int. However, I wanted to be able to > support 'null' to indicate no color (i.e. transparent). Thus, I > changed it to take an Integer instead of an int. > > However, Rhino is passing in an Integer with the value 0 when I invoke > it with a script like this: > > myObject.setBgcolor(null); > > Is there a way to get Rhino to pass me a null instead of a new > Integer(0)? Rhino treats int and Integer in the same way when calling methods in ScriptableObject subclasses which is a feature so if you really want to distingush between null and non-null arguments, change the argument type from Integer to Object to have: jsFunction_setBgcolor(Object color) { if (color == null) { .... } else { int value = ((Integer)Context.toType(color, Integer.TYPE)).intVaue(); ... } } And if you would like to treat undefined values in the same as null, change the above to: if (color == null || color == Contxt.getUndefinedValue()) { ... Regards, Igor .