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

后端 未结 5 2113
鱼传尺愫
鱼传尺愫 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:59

    The best and safest way is to use java.util.Collections method 'checkedList(List list, Class type)'

    With this method, all of the items in your old List will be checked as early as possible.

提交回复
热议问题