• 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

Generics and Collection

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. I am preparing for SCJP 5. When I give mock exams, I do bad at Generics and Collection. I am not so new to java and I have lots of ArrayList and Vector experience. But I am surely new to java 5. So Generics with collection becomes a bit confusing at times. I have SCJP Study guide(K&B). I need detailed reading on them. Can anybody guide me about that? Thanks
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Make sure you are comfortable with Generics and polymorphism - both with the type of collection and the type of elements. For example, the following statement is valid because ArrayList is a List:



But the following doesn't work, even though a String is obviously an Object:



This topic is definitely on the exam - not sure how best to learn all the details except maybe by writing some code.
 
Phal Ach
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rich Raposa. I get your point in the example. That is where I am doing wrong. Can you please tell me which would be best book that gives details about these topics? Thanks again.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Phalguni,
Kathey sierra is very nice book for SJCP 5.0 and more about Generics and collections.

Below thing is correct in Array but not correct in collection:

Object a[]=new Integer[5];//correct

consider Parent is super class and Child is sub class or Parent then

List <Parent> list=new ArrayList<Child>();//wrong thing

Cheers,
Tejas
 
Phal Ach
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tejas.
 
So it takes a day for light to pass through this glass? So this was yesterday's tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic