Writing Native JavaScript Methods
JSNI methods are declared
native
and contain JavaScript
code in a specially formatted comment block between the end of the
parameter list and the trailing semicolon. A JSNI comment block begins
with the exact token
/*-{
and ends with the exact
token
}-*/
. JSNI methods are be called just like any
normal Java method. They can be static or instance methods.
Example
public static native void alert(String msg) /*-{
$wnd.alert(msg);
}-*/;
Tip
In
hosted mode, you
can set a breakpoint on the source line containing the opening brace
of a JSNI method, allowing you to see invocation arguments.