• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

E super CharSequence makes no sense??

 
AbhishekSonu Gupta
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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.
 
Keith Nagle
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • 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
  • 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??
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic