This is the principle called:
Program to an interface, not an implementation. This is a frequently asked question on the forums here.
The most important reason to declare the type of your variable as a
List and not an
ArrayList is to decouple the interface and the implementation in your program. The program only needs to know that the list is a
List, it doesn't need to know what particular implementation of interface
List is being used. Hiding the implementation means that you can easily change it later.
For example, you might find out later that for that particular list, a
LinkedList would be more efficient than an
ArrayList (these two implementations have different performance characteristics - for example, inserting elements in the middle is more efficient on a
LinkedList than on an
ArrayList). If your variable is declared as being a
List, you would only need to change one line:
For the rest of the program,
stuff is still a
List.
If you would have made
stuff an
ArrayList, then it would be much harder to change it to a
LinkedList, because there might be places in your program where
ArrayList-specific methods are called on
stuff.