JSObject and delegation to other java classes

Marc Downie marc at openendedgroup.com
Mon Jul 21 15:34:47 UTC 2014


On Mon, Jul 21, 2014 at 6:11 AM, A. Sundararajan<
sundararajan.athijegannathan at oracle.com> wrote:

> Will this sample of any help to you?
>
> http://hg.openjdk.java.net/jdk9/dev/nashorn/file/
> 34a783929a67/samples/jsobj_example.js
>
>
It is! Many thanks.

What stopped me getting there myself? Well I fell into this trap: assigned
methods from the fallback class to temporary variables doesn't work

var ArrayList = Java.type('java.util.ArrayList')
var al = new ArrayList()

al.size() // WORKS, returns zero
var sz = al.size // works, sz is not undefined or null
sz() // throws ClassCastException

Obviously in your code you just do the lookup multiple times, but out of
interest: is there anything I can do with sz to call the underlying method?
What's it even for?

best,

Marc


More information about the nashorn-dev mailing list