| 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...
|
 |
 |
|
|
subject: Map : Serious Doubt
|
|
|