I have the following code
The above code for some reason isnt able to get the value back from the HashMap. I printed out the whole HashMap and I can see that it contains the said key and value. I have also implmented the equals method in the MyKey class but for some reason it is never called (I checked that by putting a println statement in the equals method)
Can anyone find the bug?
Originally posted by Paul McKenna:
HashMap m = new HashMap();
MyKey key = new MyKey(MyConstants.PRIMARY_KEY); // MyKey is just a wrapper class around a string constant
m.put(key, "Nothing here");
System.out.println("Value for mykey : "+key);// use the already defined key
Perhaps this might work, if Object.hashcode() is not overridden.
Thank you! I had to override the hashCode method. It worked once that was done