But why is this a trick question. When generics is applied to the map the return value would automatically be an Integer thereby not needing a cast
Because it just changed line 5. It didn't change line 2 to be generic. So the code does not compile, but the question didn't ask this...
The question probably assumes that you would change Map to be a generic ? After all the class internals are updated to be generic. I do not have the question at hand to scrutinize this more. Can you post the entire question ?
Joined: Mar 04, 2009
Deepak Bala wrote:The question probably assumes that you would change Map to be a generic ? After all the class internals are updated to be generic.
I realized what I missed. It's all the correct options combined.
It is still a trick question, because we are used to think in the options independently, and the question is not very clear (at least for me), but it is reasonable:
This class is to be updated to make use of appropriate generic types, with no changes in behavior
(for better or worse). Which of these steps could be performed? (Choose three.)
Does the exam make it clear when the correct options must be combined?
Well "clear" is a somewhat subjective term, but typically the real exam will include phrases like:
"which fragment, insert independently..."
"which three inserted together..."
In this case however it's best to include the entire question when you want to discuss a question. To some degree the portion of the question that you posted doesn't provide every detail that might be necessary to properly discuss it. No matter whose mock question you're discussing, it;s dangerous to edit the question when you post it - often the devil will be in a small detail you didn't consider.
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Joined: Mar 04, 2009
Thanks for the reply Bert!
Question 5. Chapter 7: Generics and Collections.
B, E, and G are correct.
* It automatically closes the angle bracket. There are no right angle brackets before <Integer>>