aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Collection and Generics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Collection and Generics" Watch "Collection and Generics" New topic
Author

Collection and Generics

shashank dwivedi
Ranch Hand

Joined: Mar 06, 2012
Posts: 61


Why can't I use Collection as reference type here??
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 813
    
    1
But this code compiles.
shashank dwivedi
Ranch Hand

Joined: Mar 06, 2012
Posts: 61
Himai Minh wrote:But this code compiles.

Yeah but what if we try to get it like
System.out.println(list.get(0))
shashank dwivedi
Ranch Hand

Joined: Mar 06, 2012
Posts: 61
shashank dwivedi wrote:
Himai Minh wrote:But this code compiles.

Yeah but what if we try to get it like
System.out.println(list.get(0))


actually it asks to typecast list to ArrayList<Integer> why so?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4491
    
    8

shashank dwivedi wrote:Yeah but what if we try to get it like
System.out.println(list.get(0))

Does the Collection interface have a get method defined in it? (The documentation is at java.util.Collection if you want to check).
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18992
    
    8

I think it would help if you posted an actual question. What we have is some code which doesn't support your original question, followed by some other questions about some code which you haven't posted. So, post some code and a question about that code.
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1180
Shashank,

We can try -



Regards,
Dan


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
shashank dwivedi
Ranch Hand

Joined: Mar 06, 2012
Posts: 61
Matthew Brown wrote:
shashank dwivedi wrote:Yeah but what if we try to get it like
System.out.println(list.get(0))

Does the Collection interface have a get method defined in it? (The documentation is at java.util.Collection if you want to check).

Shashank Dwivedi wrote:
Thanks Matthew I checked docs and got it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Collection and Generics