Parvathy
Parvathy

Reputation: 2465

Why GWT is not supporting all java classes or methods?

From the below link I understood that GWT supporting only a subset of classes or methods in the following package in client side.

java.lang
java.lang.annotation
java.util
java.io
java.sql

https://developers.google.com/web-toolkit/doc/1.6/RefJreEmulation#Package_java_lang

Why is it so? I think it make more problem in development because I am using only GWT client and using REST Web service instead of server.

Is there any new release of jar like gwtx (new release for supporting persistence,annotation etc) for using all classes and methods in the above packages. and my main doubt is why they are not supporting all?

Upvotes: 1

Views: 1309

Answers (1)

Thomas Broyer
Thomas Broyer

Reputation: 64561

To support translating Java to JavaScript, every standard class has to be emulated, i.e. recreated in such a way that the GWT compiler knows how to translate it to JavaScript. An ArrayList for instance is based around a JavaScript Array, String methods have to be emulated on top of a JavaScript String, etc.

And there are things that are simply impossible to emulate (files, sockets). A few other things are not emulated on-purpose, because the emulated version, while technically possible, would be much less performant than a more direct mapping of the browser APIs, and GWT strives for performance (third-party libraries, such as GWTx, can provide such emulations if needed) more than compatibility (the choice of Java as the language was primarily to leverage tooling, not provide a compatibility layer to allow reuse of existing libraries).

Finally, reflection is not supported as it would make it impossible for the compiler to prune dead code and do all its optimizations: how would it know that a particular class, field or method is not actually used by reflection rather than direct calls?

Upvotes: 8

Related Questions