简体   繁体   中英

How to get the hash code of a Javascript implemented interface

I have an interface, EventHandler (OSGi EventAdmin), with a single method handleEvent(Event).

I have the following Javascript code:

importPackage(org.osgi.service.event)

obj =
{
    handleEvent: function(event)
    {
        // some code
    }
};

handler = new EventHandler(obj);

service.registerHandler(handler, topic);

The code is executed by Rhino (more specifically Rhino as built into JRE6, JSR-223 spec). service is a Java object bound to the script context where registerHandler first looks up the handler in a Map. This fails because the NativeObject "handler" doesn't have a hashCode() method.

Is there a reason a NativeObject is missing standard Java Object methods?

What's a way to work around this?

I'm using Rhino that comes with JRE6 (1.6R2).

您的代码还不完整,但是NativeObject在我看来更像一个JavaScript对象。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM