• Post Reply Bookmark Topic Watch Topic
  • New Topic

need help with declaration  RSS feed

 
Higgledy Smith
Ranch Hand
Posts: 193
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone explain this declaration:



applicantList is being declared as a Collection type but instantiated as an ArrayList?

Thanks.
Higgledy
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37513
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Higgledy,
Right. Collection is an abstract class. This means it cannot be instantiated. ArrayList is the concrete implementation class that can be instantiated.

It is common to write the code as
Collection applicantList = new ArrayList();
rather than
ArrayList applicantList = new ArrayList();

so that callers can't make assumptions about the implementation type used. This lets the author change it more easily in the future.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!