What does this statement with List and ArrayList mean?

后端 未结 5 1687
忘了有多久
忘了有多久 2021-01-14 08:56

I am reading the Drools Planner examples and I came across code like this a lot:

List columnList = new ArrayList(n);
5条回答
  •  抹茶落季
    2021-01-14 09:26

    List is an interface and cannot be instantiated, so new List will trigger a compile-time error. You can do ArrayList columnList = new ArrayList(n);, but this way you can't easily switch between different List implementations(ArrayList is one of them).

提交回复
热议问题