• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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.
 
Sunglasses. AKA Coolness prosthetic. This tiny ad doesn't need shades:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic