View Single Post
  #4 (permalink)  
Old 01-31-2008, 08:36 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
Quote:
Originally Posted by bugger View Post
Thanks Tim. It means both can only store ArrayLists. Even arrayList1 cannot store other collections. Is this so?
That is not true. arrayList1 can store any instance of Collection, but arrayList2 can only store instances of ArrayList or any subclasses of it. For example:
Code:
Collection <String> test1 = null; ArrayList <String> test2 = null;
The following is okay
Code:
test1 = new ArrayList<String>(); test1 = new Vector<String>(); test2 = new ArrayList<String>();
The following is NOT okay
Code:
test1 = new Integer(10); test2 = new Vector<String>();
These are polymorphism concepts. I am sorry if I confused you. I'm trying my best to explain this.
__________________
If your ship has not come in yet then build a lighthouse.
Reply With Quote