You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you call a Java method through node-java, any arguments (V8/JavaScript objects) will be converted to Java objects on the v8 main thread via a call to v8ToJava (found in utils.cpp). The JavaScript object is not held on to and can be garbage collected by v8. If this is an async call, the reference count on the Java objects will be incremented. The Java method will be invoked in a node.js async thread (see uv_queue_work). When the method returns, the resulting object will be returned to the main v8 thread and converted to JavaScript objects via a call to javaToV8 and the Java object's reference count will then be decremented to allow for garbage collection. The resulting v8 object will then be returned to the callers callback function.
699
699
700
+
# Static member name conficts ('name', 'arguments', 'caller')
701
+
702
+
The Javscript object returned by `java.import(classname)` is a Javascript constructor Function, implemented such that you can create instances of the Java class. For example:
But Javascript reserves a few property names of Function objects: `name`, `arguments`, and `caller`. If your class has public static members (either methods or fields) with these names, node-java is unable to create the necessary property to implement the class's API. For example, suppose your class `Test` implements a static method named `caller`, or has a `NestedEnum` with a value `name`:
714
+
715
+
```java
716
+
publicclassTest {
717
+
...
718
+
publicstaticStringcaller() { return"something"; }
719
+
publicenum NestedEnum { foo, name };
720
+
}
721
+
```
722
+
723
+
In Javascript, you would expect to be able to use those static members like this:
Node-java can't create those properties, so the above code won't work. Instead, node-java appends a suffix to the name. The default suffix is simpy an underscore `_`, but you can change the suffix using asyncOptions:
732
+
733
+
```javascript
734
+
var java =require('java');
735
+
736
+
java.asyncOptions= {
737
+
asyncSuffix:"",
738
+
syncSuffix:"Sync",
739
+
ifReadOnlySuffix:"_alt"
740
+
};
741
+
742
+
var Test =java.import('Test');
743
+
Test.caller_alt(function(err, result) { ... }); // OK
0 commit comments