Automatic type conversions: Passing char from Java to JS

Tim Fox timvolpe at
Wed Jul 9 16:15:38 UTC 2014


I've noticed that if I pass a  java.lang.Character from Java to JS (e.g. 
via a JavaScript callback handler that is called from Java), then it is 
converted to a JavaScript object not a string.


someJavaObject.setHandler(function(char) {
   console.log(typeof char);

Then in the Java object:

class MyJavaClass {

   public void setHandler(Consumer<Character> handler) {


The following is logged:


If I instead pass a java.lang.String from Java to JS, it is converted to 
JS string as I would expect.

Intuitively I would expect a java.lang.Character to be converted to a JS 
string too.

Is the current Nashorn behaviour as expected?


More information about the nashorn-dev mailing list