To decouple your code from a specific implementation of the interface.
This also helps you to move to another implementation of the List
interface in the future.
For example -
You have List<String> names = new ArrayList<String>();
later on you decide that you should have used some other implementation of the List
interface, say LinkedList
so you would just change it to List<String> names = new LinkedList<String>();
and nothing breaks.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…