File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Non-generic collection - can hold a primitive or not? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Non-generic collection - can hold a primitive or not?" Watch "Non-generic collection - can hold a primitive or not?" New topic
Author

Non-generic collection - can hold a primitive or not?

Astha Sharma
Ranch Hand

Joined: Oct 15, 2011
Posts: 249

Hi,
In K&B 6 book page no. - 597 under topic - The Legacy Way to Do Collections, it is written that A non-generic collection is quite happy to hold anything that is NOT a primitive.
Whereas the following code works fine.

Please tell me is this an error in the book or I am misunderstanding something?


Astha - OCPJP 6 (90%)
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4421
    
    8

Remember auto-boxing. It looks like you're adding an int to the collection, but it's actually being converted to an Integer first.
Astha Sharma
Ranch Hand

Joined: Oct 15, 2011
Posts: 249

Oh yes...didn't thought about it.
Thanks Matthew
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Non-generic collection - can hold a primitive or not?