wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Map : Serious Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Map : Serious Doubt" Watch "Map : Serious Doubt" New topic
Author

Map : Serious Doubt

Sandeep Vaid
Ranch Hand

Joined: Feb 27, 2006
Posts: 390

This code compiles fine.
What does the bold line means? What type will the key and Value be of ?

I have seen mostly ;
Map<Key,Value> m = new HashMap<Key,Value>();

where both Key and Value are Objects.
[ October 28, 2006: Message edited by: Sandeep Vaid ]
Venkat Sidh
Ranch Hand

Joined: Sep 30, 2006
Posts: 61
Your code is referring to non-generic code so Key & Value be of any Objects. If you're planning to use Java object as a Key then you need to override both equals() and hashcode()
Costa lamona
Ranch Hand

Joined: Sep 24, 2006
Posts: 102
Note that

HashMap always contains two objects pair even with generics
Generics are cause "type ensurance" on compile time only.


SCJP 5
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Hi cowboys,


you all ran into the trap.


...






























the bold line doesn't refer to the collections class Map, but to Sandeep's own class called Map....
And it can never compile. Unless you have also a class named HashMap in your package that extends your Map class.

: eek :


Bu.


all events occur in real time
Sandeep Vaid
Ranch Hand

Joined: Feb 27, 2006
Posts: 390
Later i also realize that my class name is also Map.

Thanks you all . I got the answer that i wanted...
 
Don't get me started about those stupid light bulbs.
 
subject: Map : Serious Doubt
 
Similar Threads
put float into hashMap
same key for diff values in HashMap
hashCode() and equals() - How it is possible
Generics : defining their relationship in order to ovloard a method
Problem about EL ....