June 2018
Beginner
722 pages
18h 47m
English
It is a good practice, while creating an object of an ArrayList, to assign its reference to a variable of type List:
List listOfNames = new ArrayList();
More likely than not, using a variable of type ArrayList will not change anything in your program, not today, nor in the future:
ArrayList listOfNames = new ArrayList();
The preceding reference can still be passed to any method that accepts a parameter of type List. However, coding to an interface (that is what we do when we make the variable of an interface type) is a good habit in general because you never know when the requirements to your code might change and you would need to use another implementation of List, like the LinkedList class, for example. If the ...
Read now
Unlock full access