I have just started to work a little with Java and trying to compare two objects with each other by overriding the equals method. I've been debugging this for quite a while trying to understand why it keeps returning false.
I've stripped it down to make it really clear. As you can see in the picture, everything matches in the else if condition.. Why on earth is it returning false?!:
public boolean equals(Object obj) {
if(obj == null)
return false;
if(getClass() != obj.getClass())
return false;
final User user = (User)obj;
int h1 = CalculateByteArray(this.macAddress);
int h2 = CalculateByteArray(user.macAddress);
char[] c1 = this.userName.toCharArray();
char[] c2 = user.userName.toCharArray();
if(this.userName == null || this.macAddress == null){
if(user != null)
return false;
} else if(c1 != c2 || h1 != h2)
return false;
return true;
}