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
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…