Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in K&B - Generics & Collections - Question 8

 
Jeff Schuler
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the K&B book for chapter 7, question 8, it says that 'E' is one of the correct responses. When I keyed it in (and added a main method), it gave a compiler error due to incompatible types. I put asterisks around the lines in question. Can someone explain to me why it is considered a valid option?



[ July 02, 2007: Message edited by: Jeff Schuler ]
 
Remko Strating
Ranch Hand
Posts: 893
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Option E is valid. You have forgotten something in your code

Your line 17 should be



If not you have a compiler error incompatible types, because the HashMap is returning an object and not an Integer.
 
Manfred Klug
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeff Schuler:
In the K&B book for chapter 7, question 8, it says that 'E' is one of the correct responses.
You must apply all of the changes.
 
Jeff Schuler
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Manfred Klug:
You must apply all of the changes.


Ok. I was treating each change independently. So the question is asking if all generic changes were made, which ones would be valid.

Thanks.
 
Jeff Schuler
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Remko Strating:
Option E is valid. You have forgotten something in your code

Your line 17 should be



If not you have a compiler error incompatible types, because the HashMap is returning an object and not an Integer.


Option E doesn't have the Integer casted. It turns out I misunderstood the question though.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic