Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 0.42 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How do I build a Java type object at runtime from a generic type definition and runtime type parameters?
  2. class Foo<T> {
  3.     public T bar;
  4. }
  5.        
  6. class Foo<T> {
  7.  
  8.     Class<T> clazz;
  9.  
  10.     public Foo(Class<T> c) {
  11.         clazz = c;
  12.     }
  13.  
  14.     public T bar {
  15.         return clazz.newInstance();
  16.     }
  17. }
  18.        
  19. public class JsonWrapper {
  20.     private String className;
  21.     private String json; // the output of the gson.toJson() method
  22. }