2

I have a case, generate an instance dynamically ie, i have map like

Map<String,Class> classMap=new HashMap<String,Class>();
classMap.put("key1",Panel.Class);
classMap.put("key2",Panel1.Class);
classMap.put("key3",Panel2.Class);
Class clazz=map.get("key");
GWT.create(clazz);

when i compile using GWT Compile i got the exception

Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
   [ERROR] Errors in 'com/asklepian/web/Sample/sample.java'
      [ERROR] Line 19: Only class literals may be used as arguments to GWT.create()

is there is any better way to achieve the same.Thanks in advance

Abin Manathoor Devasia
  • 1,945
  • 2
  • 21
  • 47
  • 4
    http://stackoverflow.com/questions/3034881/how-to-create-new-instance-from-class-name-in-gwt –  May 18 '13 at 15:54
  • 3
    There is no reflection in GWT. You can only pass things to GWT.create() that are statically compiled into the call. – Deanna May 19 '13 at 21:26

1 Answers1

1

Retrieving class objects is done by adding lowercase ".class" to the classname.
So maybe change your map to
classMap.put("key1",Panel.class);
classMap.put("key2",Panel1.class);
classMap.put("key3",Panel2.class);
and try to recompile with that.

Leo Rohr
  • 196
  • 1
  • 8