• 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

E super CharSequence makes no sense??

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone explain why Option G is wrong in question given below(Chapter-7 question 14 of SCJP 1.5 book by kathy sierra)..???

Q. Given that String implements java.lang.CharSequence, and:


Which declarations could be inserted at // INSERT DECLARATION HERE so that the program
will compile and run? (Choose all that apply.)
A. public static <E extends CharSequence> Collection<? extends CharSequence>
getLongWords(Collection<E> coll)
B. public static <E extends CharSequence> List<E>
getLongWords(Collection<E> coll)
C. public static Collection<E extends CharSequence> getLongWords(Collection<E> coll)
D. public static List<CharSequence>
getLongWords(Collection<CharSequence> coll)
E. public static List<? extends CharSequence>
getLongWords(Collection<? extends CharSequence> coll)
F. static public <E extends CharSequence> Collection<E>
getLongWords(Collection<E> coll)
G. static public <E super CharSequence> Collection<E>
getLongWords(Collection<E> coll)

In Answer explaination it is given that Option G is wrong because
E super CharSequence makes no sense�super could be used in conjunction with a wildcard but not a type variable like E.
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
CharSequence is an interface.
Look at F, this answer is the correct version of G.
Looking at the type parameter for G <E super CharSequence>
would imply that you are declaring E as a CharSequence or a
super entity of CharSequence, not something that implements the CharSequence interface. It is an interface, so you
have to have the keyword extends which means a type that "implements" or
"is-a" CharSequence. Read page 593 again.
Best regards
 
AbhishekSonu Gupta
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply...

Tell me one more thing, if we take some other CLASS in place of CharSequence<interface> then would the option G be correct??
 
Message for you sir! I think it is a tiny ad:
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