Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Astha Sharma
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Matthew Brown
Bartender
Posts: 4565
8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh yes...didn't thought about it.
Thanks Matthew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic