Create an instance of this class

In GWT, I have a generic Class<T>one in which I want to dynamically instantiate T:

class MyGenericClass<T> {

  void foo(Class<T> clazz) {

    ...
    T t = GWT.create(clazz); //I want to instantiate T
  }

}

But I have the following compilation error:

As arguments to GWT.create ()

only class literals can be used.

So how do I instantiate this class?

In another thread, I found:

GWT.create( Reflection.class ).instantiate( YourClass.class );

But I did not find a class named Reflectionwith this instantiation method.

+3
source share
1 answer

The java document of the create method says everything

create (Class) , . , .

http://www.gwtproject.org/javadoc/latest/com/google/gwt/core/client/GWT.html#create(java.lang.Class)

, , .

GWT.create(YourClass.class)
+1

All Articles