Incoming Java type | How it appears to JavaScript code |
---|---|
a JavaScript numeric value, as in var x = 42; |
|
String | a JavaScript string, as in var s = "my string"; |
boolean | a JavaScript boolean value, as in var b = true; |
a JavaScriptObject that must have originated from
JavaScript code, typically as the return value of some other JSNI method
|
|
an opaque value that can only be passed back into Java code | |
Object | an opaque value accessible through special syntax |
Outgoing Java type | What must be passed |
---|---|
a JavaScript numeric value, as in return 19; |
|
String | a JavaScript string, as in return "boo"; |
boolean | a JavaScript boolean value, as in return false; |
a native JavaScript object, as in return
document.createElement("div") |
|
Object (including arrays) | a Java Object of the correct type that must have
originated in Java code; Java objects cannot be constructed from "thin
air" in JavaScript |
byte
,
short
, char
, int
,
long
, float
, or double
.
You must ensure the value is appropriate for the declared type. Returning
3.7
when the declared type is int
will
cause unpredictable behavior. null
and JavaScript null
are
identical and always legal values for any non-primitive Java type.
JavaScript undefined
is not identical to
null
; never return undefined
from a JSNI
method or unpredictable behavior will occur. com.google.gwt.dev.shell.HostedModeException
detailing
the problem. This exception is not
translatable and never
thrown in web mode.
return (value == null) ? null : value;
to avoid returning undefined
.