Why use GWT.create() instead of new?

RodeoClown picture RodeoClown · Feb 11, 2010 · Viewed 28.1k times · Source

What is the difference between GWT.create(SomeClass.class) and new SomeClass()?

Why would you use one over the other?

Answer

Hilbrand Bouwkamp picture Hilbrand Bouwkamp · Feb 11, 2010

GWT.create is used by the GWT compiler for deferred binding. Deferred binding is a feature of the GWT compiler that works by generating many versions of code at compile time, only one of which needs to be loaded by a particular client during bootstrapping at runtime.

You should only use the GWT.create for those cases that depend on this specific use case. For example when creating a RPC class: (MyServiceAsync)GWT.create(MyService.class). In all other cases use new.

For more information check the GWT page on Deferred binding: http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsDeferred.html