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