dimanche 20 février 2022

Creating List in runtime using Java reflection

I am trying to solve the problem of creating a List in runtime. I created method

private <GT, LT> LT getList(Class<GT> genericType, Class<LT> listLype) throws Exception {
    Constructor<LT> c = listLype.getConstructor();
    ...
    ???
}

where LT - type of List I want to create (ArrayList, LinkedList, etc), and GT - generic type of List. How can I createLT<GT> List?





Aucun commentaire:

Enregistrer un commentaire