jeudi 15 septembre 2016

How to convert a String to instance of Object by reflection in java

How to convert "java.util.List<utils.MyObject>" String to equivalent List<utils.MyObject> obj = new ArrayList<>(); by reflection in java

How to convert "java.util.Map<java.lang.String, java.lang.String>" String to equivalent Map<java.lang.String, java.lang.String> obj = new HashMap<>(); by reflection in java

How to convert "utils.MyObject" String to equivalent utils.MyObject obj = new utils.MyObject(); by reflection in java

My input is a String, example:"java.util.List<utils.MyObject>"

I need create a instance of Object and add in a array (List<Object> result = new ArrayList<Object>();).

Object obj = ...????("java.util.List<utils.MyObject>")
result.add(obj);





Aucun commentaire:

Enregistrer un commentaire