title: How to unbox values returned by javascript (nashorn) in Java object?
body: <p>I have the following program, which executes Javascript in Java (nashorn) . The Javascript code is returning an object.</p>
  
  <pre><code>public Object execute(){
          ScriptEngineManager sem = new ScriptEngineManager();
          ScriptEngine e = sem.getEngineByName("nashorn");  
          Invocable invocable = (Invocable)e;
          ScriptEngineFactory f = e.getFactory();
          Object result;
          try {
              String statement = "function fetch(value, count) { count++ ; return {'value': value,'count' : count} }; } ; ";
              CompiledScript cs = ((Compilable)e).compile(statement);
              cs.eval();
              result = invocable.invokeFunction("fetch", 10,2);
  
          }   
          catch (Exception se ) {
              String version = System.getProperty("java.version");
              System.out.println(version);
              result = "script exception ";
          }
  </code></pre>
  
  <p>How do I access the object values in my result object in Java? 
  Initially, I tried using <code>result.toString()</code> to get results. Seems to <code>return [Object Object]</code></p>
  
  <p>Is there a way, where I could return the results to <code>result</code> object such that I could get values equivalent to <code>result.value</code> , and <code>result.count</code> (similar to Javascript) .</p>