Hi,
If the Map class takes Object as parameters for all its methods, how can I put objects belonging to any other type into the map. For example, if I want to do:
Map a = new HashMap() ;
long id ;
String bookname ;
a.put(id,bookname) ;
It doesn't work..I get a compile error on the a.put line saying the parameter's types are wrong.. If I try casting the parameters to (Object) like
a.put((Object) id, (Object) bookname) ;
I get the error that the types cannot be casted into Object. I'm confused. All classes inherit from Object so why does the cast generate compile error. How do I accomplish the task above? If this is not it, what is the workaround? I thought Maps were so you could use them with any types..
Thanks.
Saad