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

后端 未结 12 1975
你的背包
你的背包 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 18:08

    I'd put it this way: While List and List can contain any type of objects, List contains elements of an unknown type, but once that type is captured, it can only contain elements of that type. Which is why it is the only type safe variant of those three, and therefore generally preferable.

    提交回复
    热议问题