• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Generics -really very hard question

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
for the following line what are legal

Map<Integer,String> map=new HashMap<Integer,String>

what are legal

1. for(Map.Entry pairs :map.entrySet()){}
2. Iterator i=map.entrySet().iterator();
3. Iterator i=map.iterator();
4. Iterator<Map.Entry<Integer,String>> i=map.entrySet().iterator();
5. Iterator<Map.Entry> i=map.entrySet().iterator


in the question i couldn't understand anything and i am totally blank
can any one please guide me regarding the each answer and state
why it is legal or illegal

Please do help me in this regard and thanks in advance
 
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I would strongly suggest you paste all this into a java editor:



You'll see some errors. I fix some lines in your code which I thought were typo, but you know better, make sure you have the correct text.

Lines 3 and 5 give me errors:
3: Map doesn't have the iterator method, would need to be casted.
5: <Map.Entry> does not match the declared <Integer,String>

Alex
 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am getting compilation errors for lines 2,3,4 and 5. Can someone please explain in details.
 
There is no "i" in denial. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic