• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

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

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic