Hello, there! I have just started to study for the SCJP 5.0 exam using the "Sun Certified Programmer for Java 5 Study Guide", by Kathy Sierra and Bert Bates. I'd like to share with you a possible mistake that the authors commited in the question number 16, page 634 (Chapter 7, "Generics and Collections"). The answers are supposed to be letters "B", "E" and "F", but if you try to compile the code using any of this "possible" answers, IT WON'T COMPILE . When using letter B, for example, the compiler error is as it follows:
"Type mismatch: cannot convert from List<capture-of ? super Integer> to List<Integer>"
You'll get similar errors if you use options "E" or "F".
To sum up: in my opinion, the correct answer would be letter "G. none of the above".
Please, Kathy and Bert, I would love that you both post any consideration regarding this question. Does it all of this story make sense or did I misunderstand ithe question? Best wishes,
P.S.: Letters "B", "E" and "F" may be corrected like this:
B. ArrayList<Integer> input = null; List<? super Integer> output = null;
E. List<Number> input = null; List<? super Number> output = null;
F. List<Integer> input = null; List<? super Integer> output = null;
Another possible answer, which is not covered by the question but is quiet interesting to think about, is this: List<Number> input = null; List<? super Integer> output = null; [ February 18, 2006: Message edited by: Fernando Matias Valadao ]
"In the case of a nuclear attack, the protection of our records is essential, if this country is to carry on its economy and maintain our way of life."
It turns out you re-discovered an errata that we discussed here a few weeks ago. We're going to collect all the errata we've received so far (which, relatively speaking, have been few ), and post them on the wickedlysmart.com website. When we post the errata list, we'll post the link here.
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Fernando Matias Valadao
Joined: Feb 19, 2003
Hello, Bert! Thanks for replying promptly and I'm sorry for not searching the forums before posting this issue. Regards,
Fernando. [ February 18, 2006: Message edited by: Fernando Matias Valadao ]