The documentation is pretty unambiguous on this point: http://google-web-toolkit.googlecode.com/svn/javadoc/2.1/com/google/gwt/core/client/GWT.html#create(java.lang.Class)
"The argument to create(Class) must be a class literal because the web mode compiler must be able to statically determine the requested type at compile-time. This can be tricky because using a Class variable may appear to work correctly in hosted mode." That restriction makes sense when you consider that GWT needs to generate the appropriate JavaScript code for the specified Java class at compile-time. On Jan 7, 8:24 pm, zixzigma <[email protected]> wrote: > with GWT.create(Foo.class), > it is possible to instantiate Foo object from Foo.class. > > however GWT.create mandates the argument passed to create method to be > a class literal, known at compile time. > > in cases where the argument is not a class literal, for example coming > from a map, > is there an alternative way to create object Foo from its Foo.class ? > > for example, lets say we have a map populated like below: > > // this map is populated > Map<ObjectA, Class<? extends Foo>> map; > > Foo lookupFoo(ObjectA objectA) { > > Class<? extends Foo> fooClazz = map.get(objectA); > > return GWT.create(fooClazz); > > } > > this works in hosted mode, but doesnt compile. > > is there any alternative way that this can be achieved without early > eagerly instantiation Foo objects ? > > the good thing about GWT.create is that it creates the object on > demand. (i believe ?) -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
