On 11/06/2010 1:19 AM, manoelhc wrote:
Is possible to use "import static" like java 5/6 on Rhino or do
something like?

No, but you could hack something like it.  For simple constants, just do:

  const EXIT_ON_CLOSE =
    Packages.javax.swing.WindowConstants.EXIT_ON_CLOSE;

in the scope that you want it. If it's a static variable, you might want to define a getter so that you can always get the current value of it. I don't think you can get access to the current activation object to make a local variable be a property with a getter. But if you're happy with it on the global object, you can do:

  __defineGetter_
    ("out", function() { return Packages.java.lang.System.out });

(I don't know that System.out would ever change value, but you get the idea.)

For static methods, then again just assigning the value to a variable should work:

  const exit = Packages.java.lang.System.exit;


So if you're happy with these all being defined on the global object (like Rhino's importClass and importPackage do), then it shouldn't be hard to write an importStatic function yourself.
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to