title: Passing common types between Java and (Rhino) Javascript
body: <p>I'm unclear on the rules for how types are converted between Javascript and Java when using (Mozilla) Rhino.</p>
  
  <p>There's some specifics in the documentation about <code>String</code>:</p>
  
  <blockquote>
    <p>It's important to keep in mind that Java strings and JavaScript
    strings are not the same […]Rhino provides some help in reducing the
    differences between the two types. First, you can pass a JavaScript
    string to a Java method that requires a Java string and Rhino will
    perform the conversion. We actually saw this feature in action on the
    call to the java.lang.String constructor in the preceding example.
    Rhino also makes the JavaScript methods available to Java strings if
    the java.lang.String class doesn't already define them</p>
  </blockquote>
  
  <p>But what about others? If I pass a javascript Number to a Java method expecting <code>int</code>, <code>double</code> (or <code>Integer</code> or <code>Double</code>) will it get converted? What about <code>long</code>/<code>Long</code>? (which won't fit in a <code>Double</code> and so won't fit in a JS number?</p>
  
  <p>What about Java methods returning these values?</p>
  
  <p>Then there's <code>Boolean</code>/<code>boolean</code>. Are the JS constants <code>true</code> and <code>false</code> converted to and from the appropriate Java value? I've seen code like</p>
  
  <pre><code>java.lang.Boolean.TRUE.booleanValue()
  </code></pre>
  
  <p>used from JS, so at least some people think it isn't.</p>
  
  <p>I have looked at the Mozilla Rhino documentation but do point out if I've missed something obvious.</p>