java - How create instance of generic class with result of Class.forName -


can create instance of generic class without knowing type parameter? have 'class' type, have been obtained class.forname (classname);

//generic class  public class mappedfield<t> extends field {     private t value;     private string sourcename;  public mappedfield(string name, string sourcename, fieldtype type){     super(name, type);     this.sourcename = sourcename; }      public mappedfield(string name, string sourcename, fieldtype type, boolean key){     super(name, type, key);     this.sourcename = sourcename; } 

}

//here's situation      string columnname = field.getsourcename() != null ? field.getsourcename() : field.getname();             class c = class.forname(field.gettype().getfullclassname());                          //i need if `field.gettype() = "integer"`: `mappedfield<integer> objfield = new mappedfield<integer>(field)`;             mappedfield objfield = new mappedfield(field);              objfield.setvalue(getfield(c, rset, columnname));                         object.getvalues().add(objfield); 

edit: it's have "java.lang.integer" , want mappedfield

the generic type erased classes , interfaces on successful compilation.on runtime not possible detect generic type.

refer link: use reflection create generic parameterized class in java


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -