On Apr 24, 8:17 pm, [EMAIL PROTECTED] wrote:
> The exception actually happens at the "Child.prototype.foo =" part.
>
> On Apr 24, 2:26 pm, [EMAIL PROTECTED] wrote:
>
> > I am having trouble properly extending Java classes with Rhino.
>
> > I am using the Mozilla version of Rhino and not the builtin version
> > with Java 6.
>
> > ------------------------ Java code to extend
> > ---------------------------------
> > public class Test {
>
> >         public int value = 4;
>
> >         public void foo() {
> >                 System.out.println(this.value);
> >         }
>
> > }
>
> > ------------------------ Javascript code
> > ---------------------------------
>
> > // Wrap the Java class into an adapted Javascript constructor
> > function Parent() {
> >         return new JavaAdapter(Test, this);
>
> > }
>
> > // Define a constructor for Child()
> > function Child() {
>
> > }
>
> > // Copy the parent's prototype into the child prototype
> > Child.prototype = new Parent();
>
> > // Override the java version of foo()
> > Child.prototype.foo = function() {
> >                 this.value = 1;
>
> >                 // call the "super" java version of this method
> >                 Parent.prototype.foo.call(this);
>
> > }
>
> > // Create an instance and test method
> > var t = new Child();
> >         t.foo(); <------ Exception gets thrown here
>
> > ----------- Error message from Rhino ------------------------
>
> > Java method "foo" cannot be assigned to. (#14)
>
> > This code works when modified to be totally Javascript based. I don't
> > believe it's an issue with the Javascript part. Am I going about this
> > the wrong way? Is it possible to actually extend Java classes?
>
> > Thank you for you help.

Great, thanks for the help guys. Since Rhino is apparently incapable
of such a simple feature, I will look elsewhere for scripting support.
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to