Let's say we have a class Teacher that contains a List<Student>:
class Teacher
{
private List<Student> list;
public Teacher(){ list = new LinkedList<>(); }
}
Because we have declared the list to be referenced by List<> then we can only use methods that can be found in the List interface. My question is: what is the point and why bother? What is the point of making it a List<> since i will not be able to use all the goodies that come from LinkedList as addFirst() addLast() etc.
One obvious advantage is when we have:
public void print(List<Student> list){}
Yes, in this case, if we pass in ArrayList or LinkedList or something else,it will work. Thats great. But what is the point of underlying data structure if we can only manipulate it via List interface.
Hope i made my question clear. Hard to put the idea across. Thanks.

New Topic/Question
Reply


MultiQuote







|