What are the risks of explicitly casting from a list of type List<? extends MyObject> to a list of type List in Java?

后端 未结 5 1162
说谎
说谎 2021-01-12 16:26

I think the title should explain it all but just in case...

I want to know what risks and potential issues relating to casting can arise from the following snippet o

5条回答
  •  迷失自我
    2021-01-12 16:27

    This is similar to

    List obj = (List) new ArrayList();
    
    
    

    I hope the problem is evident. List of subtypes can't be cast to Lists of supertypes.

    提交回复
    热议问题