Converting non-generic List type to Generic List type in Java 1.5

后端 未结 5 2208
鱼传尺愫
鱼传尺愫 2021-02-07 06:21

I have a List that is guaranteed to contain just one type object. This is created by some underlying code in a library that I cannot update. I want to create a List
5条回答
  •  眼角桃花
    2021-02-07 06:55

    You can simply cast the list:

      List raw = new ArrayList();
      List generic = (List) raw;
    

提交回复
热议问题