• Post Reply Bookmark Topic Watch Topic
  • New Topic

Paramaterized Collection types, and primitive vs Object  RSS feed

 
Joe Vahabzadeh
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All,

Ok, I was forced to work with making things JRE 1.4.2 compatible until very recently.

So, now that I only have to be sure of 1.5 compatibility, I get to use all those nifty parameterizations with Collection objects, such as doing Vector<String> instead of just Vector.


However, I accidentally did something that appears to work, although it seems it shouldn't.

I created a Hashtable<String, Integer>

Then, without paying careful attention, I did something like the following:



Now, is it just that the Collections know to allow a primitive equivalent of an object, or is this something that's generally not safe to do? I was surprised that neither Eclipse, nor the compiler, complained, and that the program worked as expected.

Or is there documentation somewhere that explains this? I might've overlooked it...

Thanks in advance.
 
Robert Hill
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is the autoboxing feature. java handles the conversion between primitives and there respective wrapper class.
 
Qussay Najjar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check this link:
http://www.whizlabs.com/tutorial/scjp/j-scjp-9-3.html
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!