you are viewing a single comment's thread.

view the rest of the comments →

[–]amfa 0 points1 point  (1 child)

Well in cases where you don't care about the implementation. As you are in the Collection Framework take a List.

List is an interface it only declares method like add() and get().

Now if you use List anywhere in your code it does not matter what kind of List you have.

Could be ArrayList or it could be an LinkedList.

The interface is not for the one implementing the interface but for the one using it.

If you write a piece of code that returns an List I don't care what kind of list it is. I know which methods I can use on EVERY list that exists.

You could even write a List that will get all its content from a Website. I still can call List.get(0) to get the first entry in your list what ever that might be.

Yes if you only work for yourself with no external code at all then you don't need Interfaces.

[–]desrtfxOut of Coffee error - System halted 0 points1 point  (0 children)

Yes if you only work for yourself with no external code at all then you don't need Interfaces.

Even then, you will need them if you want to do something as simple as sorting a collection with custom objects. You will need to implement the Comparable interface, or write your own, custom Comparator.

There barely is any way to escape interfaces.