• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Collection Generics SCJP 6.0

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

I was reading this topic, generic mixed up with non-generics.

List<Integer> table = new ArrayList<Integer>();
for(int x=0;x<5;x++)
table.add(x); // autoboxing is done automatically

int y = table.get(3); //unboxing and cast is done automatically.



in case i change the List declaration to non-generic, than


List table = new ArrayList();
for(int x=0; x < 5; x++)
table.add(x); // it should work, i mean automatically autoboxing it

int y = (Integer) table.get(3); // i'm doing the casting, but what about the unboxing, is it done automatically???


finding these topics interesting, but isn't this Collection chapter very vast in this bert bates and siera book ??? i mean if any topic is being eliminated from the exam objective (like serialization .... ) ....

thanks guys, hoping that i be able to appear for exam by 10 or maximum 15th of feb 2010.

regards,

Rafi

 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post code inside CODE tags

table.add(x); // it should work, i mean automatically autoboxing it



It would not because collections that do not use generics will default to storing objects. An int cannot be boxed to an Object
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic