Java List vs ArrayList

前端 未结 7 1748
有刺的猬
有刺的猬 2020-12-07 01:14

As a C++ oldtimer I have managed to solve my problem but I can not wrap my head around the underlying Java mechanisms here:

Vector x = new Vec         


        
      
      
      
7条回答
  •  既然无缘
    2020-12-07 01:53

    List is an interface and an interface can't be instantiated.

    It's used to implement polymorphism. i.e. a reference of interface type can hold object of any class that implements it.

    List zzz = new ArrayList();
    
    
    

    it works, cause ArrayList implements List.

    提交回复
    热议问题