Java Generics: List, List<Object>, List<?>

后端 未结 12 1974
你的背包
你的背包 2020-11-22 17:08

Can someone explained, as detailed as possible, the differences between the following types?

List
List
List


Let me m

12条回答
  •  一生所求
    2020-11-22 17:54

    Simplest explanation which is not "RTFM":

    List
    

    Will generate lots of compiler warnings, but is mostly equivalent to:

    List
    
    
    

    While:

    List
    

    basically means its something generic, but you don't know what the generic type is. Its great for getting rid of compiler warnings when you cant modify the return types of other things that just returned List. Its much more useful in the form:

    List
    

    提交回复
    热议问题