jeudi 15 septembre 2016

How to convert a String to List

when I code in hard, it works.

List<Object> result = new ArrayList<Object>();
List<MyObject> conditions = new ArrayList<>();
result.add(object);

I need convert a String("java.util.List<utils.MyObject>") to List of MyObject by reflection in java.

List<Object> result = new ArrayList<Object>();
// reflection
    Class<?> c = Class.forName("java.util.List<utils.MyObject>");
    ...
    ...
    Object object = myList.newInstance();
// end reflection
result.add(object);





Aucun commentaire:

Enregistrer un commentaire