How to pass argument to Generic type class in java -


i have class similar given below

public class myclass<k,v>{   public myclass(properties prop){   map<k,v> mymap = new hashmap<k,v>();  }  } 

i need invoke class passing string k , v myanotherclass , myanotherclass taken user input through file, how create myanotherclass given name file, , pass same myclass<string,myanotherclass> = new myclass<string,myanotherclass>() . best way achieve same.

any appreciated.

thanks

java erases types on compilation, need have user pass in type (by passing in class object of type) @ runtime.

import java.util.properties; import java.util.hashmap; import java.util.map;  public class myclass<v extends class<v>> {      public myclass(properties prop, v type){         map<string,v> mymap = new hashmap<string,v>();     }  } 

will give need. called like

new myclass(properties, customer.class); 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -