I override the equals method in the Friends class, yet I do not see the value "Spring 2002". Rather I see the value "null" instead. Did I miss something in my code?
package com.n2n.blotter.core.junit;
import java.util.*;
public class Birthdays {
public static void main(String[] args){
Map<Friends, String> hm = new HashMap<Friends, String>();
hm.put(new Friends("Charis"), "Summer 2009");
hm.put(new Friends("Draumer"),"Spring 2002");
System.out.println(hm.get(new Friends("Draumer")));
}
}
class Friends{
String name;
Friends(String n){
this.name = n;
}
public boolean equals(Object obj){
Friends f = (Friends)obj;
if(this.name==f.name)
return true;
return false;
}
}