Child pages
  • GWT JSNI inheritance antifeature
Skip to end of metadata
Go to start of metadata

References to java methods from JSNI must always refer to the class signatures of the defining base class, not the inheriting child class. Compile-time- OR Runtime-Exceptions can occur.

Example: Take the following abstract class...

package org.clazzes.example; 
abstract class Parent {

  public void parentMethod() {
    //Do something...
  }

}

which is extended as follows (factory method added for clarity):

package org.clazzes.example;
class Child extends Parent {

  public static Child getInstance() {
    return new Child();
  }

}

To use parentMethod() from an instance of Child, you must use the following:

public native final void callParentMethodFromJSNI() /*-{
  var child = @org.clazzes.example.Child::newInstance()();

  //access to parentMethod() only works like this:
  child.@org.clazzes.example.Parent::parentMethod()();

}-*/;
  • No labels