Return type binding
A. Sundararajan
sundararajan.athijegannathan at oracle.com
Wed Sep 10 12:27:59 UTC 2014
I think you can use javax.script.Invocable API
ScriptEngineManager m = new ScriptEngineManager();
ScriptEngine e = m.getEngineByName("nashorn");
// your script may evaluate to a Person (script object) instance
Object obj = e.eval("... your script here...");
Invocable invocable = (Invocable)e;
MyInterface infObj = invocable.getInterface(obj, MyInterface.class);
Hope this helps,
-Sundar
On Tuesday 09 September 2014 06:58 PM, Alex Soto wrote:
> Hi,
>
> currently I am developing an application with Java that may use Nashorn to
> communicate with a Javascript (Opal rendered) javascript files. I would
> like to know if it is possible to create a proxy interface against return
> type.
>
> Today I have seen this example:
>
> function Person(firstName, lastName) {
> this.firstName = firstName;
> this.lastName = lastName;
> this.getFullName = function() {
> return this.firstName + " " + this.lastName;
> }
> }
>
> static void fun4(ScriptObjectMirror person) {
> System.out.println("Full Name is: " + person.callMember("getFullName"));
> }
>
> I would like to know if you can bind ScriptObjectMirror to an interface (in
> this case Person interface) so instead of callMember you can call directly
> the interface.
>
> So basically I could do in java:
>
> Person p = .convert(engine, person, Person.class)
>
> For example in JRuby world you can do it.
>
> Thank you so much for your help,
> Alex.
>
>
More information about the nashorn-dev
mailing list