object from Java. Such classes must conform to a number of restrictions
so that the compiler can implement them. This page lists those
In the following, "JSO class" means any subclass of
Rationales are written like this.
- All instance methods on JSO classes must be one of:
explicitly final, a member of a final class, or private. Methods
of JSO classes cannot be overridden, because calls to such methods
could require dynamic dispatch.
- An interface type may be implemented by at most one JSO
subtype. This ensures that polymorphic dispatch via a
"SingleJsoImpl" interface can be statically resolved to exactly one
implementing JSO subtype.
"SingleJsoImpl" interface may be further extended. The subclasses
may implement additional "SingleJsoImpl" interfaces. The
methods on a JSO must be effectively final, so each "SingleJsoImpl"
method still has a 1:1 mapping to a method defined within a JSO
- It is valid for any number of any non-
types to implement a "SingleJsoImpl" interface. There is a
slight runtime dispatch penalty when a "SingleJsoImpl" interface is
implemented by both JSO and non-JSO types.
- No instance methods on JSO classes may override another
method. This catches accidents where JSO itself did not
finalize some method from its superclass.
- JSO classes cannot have instance fields. The fields
would have no place to live in web mode. Programmers should instead
make an explicit wrapper class and put the fields there.
- Nested JSO classes must be static. The implicit
fields of a non-static inner class has the same problems as an
- "new" operations cannot be used with JSO classes. This
avoids ever being able to try to instantiate JSO objects using the new
keyword. New JSO instances can only come from JSNI, as in previous
versions of GWT.
- JSNI methods may not refer to instance methods defined within
- Every JSO class must have precisely one constructor, and it
must be protected, empty, and no-argument.