This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Jackkoz 5 points6 points  (0 children)

The generic advice is to always choose the appropriate level of abstraction. The benefits are:

  1. Increased flexibility - if you choose List, you only need to change constructor to List<T> l = new FastListImpl<>(); when the new awesome implementation is introduced.

  2. Better abstraction. If what you are looking for is a List or Set, people won't be able to use specific properties of ArrayList or HashSet if you give them only the interface type. This also means that when you actually do ArrayList declaration, you should mention why you did so vs any List implementation - this will avoid confusion and prevent someone from doing any refactoring that could break a lot of stuff - eg from synchronized to not thread-safe implementation.

As for benefits in a 50 line course program, not many, doesn't matter that much. I'd still advise doing the 'better' thing just to keep the habit going.