From:  Nico Krebs <>
Date:  27 Jul 2012 01:49:45 Hong Kong Time

Mozilla Rhino: Defining Java Methods of an overloaded Class as global JavaScript function


Hey Igor,

i'm having trouble with the following:

if have two JAVA classes A and B while B extends A and overloads a method of A:

class A{a(){return "a"}}
class B extends A{ a(){return "B"}}

now i'd like to be able to execute "a()" in javaScript on Rhino.

usually, on non-overloaded java methods i would do the following when initializing the rhino engine:
scope.defineFunctionProperties("a", new B().getClass(), ScriptableObject.DONTENUM);

but when i'm doing this, i get the following exception:

Method "a" occurs multiple times in class "B".

i also tried to use a different name in class B and i got this exception:

TypeError: Method "a" called on incompatible object. 

I would be really happy about any suggestions :)