Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Map : Serious Doubt

 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that

HashMap always contains two objects pair even with generics
Generics are cause "type ensurance" on compile time only.
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Later i also realize that my class name is also Map.

Thanks you all . I got the answer that i wanted...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic