• 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

Help for generics

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
I have Sun certified programmer for java 5 of Kathy-Bates.
In 'Self test' of 'Generics and Collections' Charpter 7. Question 14 there are some things which i did not understood properly. Code is as follow-

Questions are as follow -
1.If <E extends CharSequence> is same as <? extends CharSequence>, how come longWords.add(word) can be used. If collection type contains extends then you cannot use add method. Here how it is possible?
2.Why i cannot say in getLongWords() as follow?
Collection<E> longWords = new ArrayList<String>();
As String implements CharSequence, it should work fine here. But i get compile time error.
3.How come there is compile time error on line
Collection<String> resultList = getLongWords(list);
If i change the method declaration as follow ?
static public <E extends CharSequence> Collection<? extends CharSequence> getLongWords(Collection<E> coll) {
4.Will there be questions in SCJP cx-310-055 on generics combined with overriding?
5.Please tell me which book is good for generics from the point of view of understanding and explaination?
Please help me!
Thanks in advance
Sharmila
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

1.If <E extends CharSequence> is same as <? extends CharSequence>, how come longWords.add(word) can be used. If collection type contains extends then you cannot use add method. Here how it is possible?


Why ? , this is legal method declaration.

2.Why i cannot say in getLongWords() as follow?
Collection<E> longWords = new ArrayList<String>();
As String implements CharSequence, it should work fine here. But i get compile time error.


Which compiler error?

3.How come there is compile time error on line
Collection<String> resultList = getLongWords(list);
If i change the method declaration as follow ?
static public <E extends CharSequence> Collection<? extends CharSequence> getLongWords(Collection<E> coll) {


Look, you are mixing concrete type parameter with that of wildcard parameter. The creation of wildcard parameterized type objects are discouraged, Why ? look at here.


4.Will there be questions in SCJP cx-310-055 on generics combined with overriding?


Can't say, better you checked out the generics syllabus from SUN website.

5.Please tell me which book is good for generics from the point of view of understanding and explaination?


From the exam point view, both K&B and Khalid & Rolf's book cover generics, which you need to know for exam. For getting master degree in Generics, here is the link
 
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sagar Rohankar wrote:For getting master degree in Generics, here is the link



the FAQs links is notworking..

Just here to correct this url.. : link
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Muhammad Saifuddin wrote:

Sagar Rohankar wrote:For getting master degree in Generics, here is the link


the FAQs links is notworking..
Just here to correct this url.. : link


Oops, Sorry !! May be its because of inexperience use of "Quick Reply" ..
 
Sharmila Punde
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Muhammad and Sagar,
Thank you very much for the link.
I will read it now.
Thanks,
Sharmila.
 
Dinner will be steamed monkey heads with a side of tiny ads.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic