Gwt doesn't support that.
GWT.create() only works with class literals.
If you know what classes you'll need you can write a method like this:
<T> T instantiate(Class<T> clazz) {
if (clazz.equals(Foo.class)) {
return new Foo();
} else if (clazz.equals(Foo2.class)) {
return Foo2();
}
throw new IllegalStateException("Class no supported: " +
clazz.getName());
}
You also can put together a generator to create it for you:
http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=gwt+generator
On Sat, Jan 8, 2011 at 12:24 AM, 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]<google-web-toolkit%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
>
>
--
Guit: Elegant, beautiful, modular and *production ready* gwt applications.
http://code.google.com/p/guit/
--
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.