How to set the generic type of an ArrayList at runtime in java?

前端 未结 4 1096
攒了一身酷
攒了一身酷 2020-12-07 01:32

Ok, so I am setting up my own XML serialization (I know there are others out there, even some built in to Java, but I am doing it myself to learn and because it is so awesom

4条回答
  •  执念已碎
    2020-12-07 02:06

    else what you can do (if you have limited number of classes).. you make a check of object by using 'instance of' operator and depending upon that place that in your arraylist

    if(obj instance of abc)
        ArrayList al = new ArrayList();
    

    you can have nested if else or switch

提交回复
热议问题