List vs ArrayList

后端 未结 6 565
春和景丽
春和景丽 2021-01-23 20:31
List> listeners = new List>();

Why the line above fails with:

Cannot in

6条回答
  •  执念已碎
    2021-01-23 20:44

    The proper way is:

    List> listeners = new ArrayList>();
    
    • refer to an object by its interface (List)
    • instantiate the object with its concrete type (ArrayList) (interfaces can't be instantiated)

提交回复
热议问题