What is the difference between declaring List vs ArrayList?

前端 未结 7 1908
北荒
北荒 2020-12-20 15:41
List mylist = new ArrayList();

ArrayList mylist2 = new ArrayList();

I am wondering wha

7条回答
  •  伪装坚强ぢ
    2020-12-20 16:37

    I know that List is an interface that ArrayList class implements.

    That's exactly the difference :)

    When you're using the two variables (mylist) and (mylist2) in code, you would have access to any methods that ArrayList defines that aren't part of the basic List interface only on mylist2.

提交回复
热议问题