graaljs
graaljs copied to clipboard
Access to static Java members via subclass [interop]
I can't access public static fields, while I can access public static methods:
console.log(Java.type('java.util.Calendar').getInstance()); // OK, prints the instance
console.log(Java.type('java.util.GregorianCalendar').getInstance()); // OK, prints the instance
console.log(Java.type('java.util.Calendar').DAY_OF_MONTH); // OK, prints "5"
console.log(Java.type('java.util.GregorianCalendar').DAY_OF_MONTH); // undefined
Is this deliberate?
For comparison with graal.js ancestors:
- Rhino allowed both access to fields and methods via subclasses.
- Nashorn allowed none - only directly declaring class could be used, see https://stackoverflow.com/questions/38226309/inherited-static-methods-not-available-in-java-nashorn
Thanks for the report! I think this inconsistency is not deliberate and we should change it (I'd prefer to disallow access via subclass). Either way, I'd highly recommend to always refer to static members via the declaring class.
Internally tracked as GR-22868.