How to cast generic List types in java?

后端 未结 9 983
离开以前
离开以前 2020-12-09 17:33

Well, I have a class Customer (no base class).

I need to cast from LinkedList to List. Is there any clean way to do this?

Just so you know, I need to cast it

9条回答
  •  -上瘾入骨i
    2020-12-09 18:16

    LinkedList implements List, so you can implement

    List< String > list1 = new LinkedList< String >(); 
    

    Or do you want to cast from LinkedList< String > to List< int >? in this case you have to pick every single element and convert it to an integer.

提交回复
热议问题