List versus ArrayList as reference type?

arraylist, interface, java, list

Solution

If you use the first form, you are saying all you are ever going to use is the functionality of the `List` interface - nothing else, especially nothing extra added by any implementation of it. This means you can easily change the implementation used (e.g. just substitute `LinkedList` for `ArrayList` in the instantiation), and not worry about it breaking the rest of the code because you might have used something specific to `ArrayList`.

Problem

Ok so I know that `Set`, `List` and `Map` are interfaces but what makes the first line of code any better than the second line? ``` List myArr = new ArrayList(); ArrayList myArr = new ArrayList(); ```

Original source