If you do not want to follow the path of generating bytecode at runtime (using BCEL , as shown below), then no. You can do this using interfaces using proxy classes , but there is no equivalent for abstract classes.
If you really want to try BCEL, your best strategy is this:
- Write a method that BCEL uses to generate
byte[] bytecode for a new class that extends the abstract class and delegates each abstract JavaScript method. - Define a naming convention that binds abstract classes with a wrapper, for example.
foo.MyAbstractClass corresponds to foo.MyAbstractClassDynamicLangWrapper . - Move a
ClassLoader that implements findClass to recognize this naming convention and generate class bytes and defineClass calls - Make sure your scripting language uses your custom class loader to resolve class names in scripts. I think in Rhino you are using setApplicationClassLoader , but I'm not sure.
source share