Monkey patching a Java class?

HRJet hrjet9 at
Wed Apr 16 18:33:20 UTC 2014

Is it possible to monkey patch a Java class for use within Javascript?

For example, I want to add a convenience method to class, say

Then, in javascript I want to call file.readAsString()  where file is an
instance of Note that the file instance may be created by
some third-party code, over which I have no control.

In Java land, this seems to be usually done with CGLib or AspectJ, etc.

I was wondering if nashorn had some trick up its sleeve for doing this in
script land, since this sort of thing is common in Javascript.


More information about the nashorn-dev mailing list