Language Support
Intrinsic types: byte
, char
, short
, int
, long
, float
, double
, Object
, String
, and arrays are supported. However, there is no 64-bit integral type in JavaScript, so variables of type long
are mapped onto JavaScript double-precision floating point values. To ensure maximum consistency between hosted mode and web mode, we recommend that you use int
variables.
Exceptions:try
, catch
, finally
and user-defined exceptions are supported as normal, although Throwable.getStackTrace()
is not supported for web mode. See Throwable for additional details.
Assertions:The GWT compiler parses Java assert
statements, but it does not emit code JavaScript code for them.
Multithreading and Synchronization:JavaScript interpreters are single-threaded, so while GWT silently accepts the synchronized
keyword, it has no real effect. Synchronization-related library methods are not available, including Object.wait()
, Object.notify()
, and Object.notifyAll()
Reflection:For maximum efficiency, GWT compiles your Java source into a monolithic script, and does not support subsequent dynamic loading of classes. This and other optimizations preclude general support for reflection. It is possible to query an object for its class name using GWT.getTypeName(Object).
Finalization:JavaScript does not support object finalization during garbage collection, so GWT isn't able to be honor Java finalizers in web mode.
Strict Floating-Point:The Java language specification precisely defines floating-point support, including single-precision and double-precision numbers as well as the strictfp
keyword. GWT does not support the strictfp
keyword and can't ensure any particular degree of floating-point precision in translated code, so you may want to avoid calculations in client-side code that require a guaranteed level of floating-point precision.
Some specific areas in which GWT emulation differs from the standard Java runtime:
Tip: You'll save yourself a lot of frustration if you make sure that you use only translatable classes in your client-side code from the very beginning. To help you identify problems early, your code is checked against the JRE emulation library whenever you run in hosted mode. As a result, most uses of unsupported libraries will be caught the first time you attempt to run your application. So, run early and often.
Whenever possible, GWT defers to browsers' native user interface elements. For example, GWT's Button widget is a true HTML <button>
rather than a synthetic button-like widget built, say, from a <div>
. That means that GWT buttons render appropriately in different browsers and on different client operating systems. We like the native browser controls because they're fast, accessible, and most familiar to users.