Hi guys,
I'm seeing a lot of equals() methods being implemented this way :
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
EncryptedData that = (EncryptedData) o;
...
This is not the best practice. Here is what should be used instead :
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof EncryptedData) {
return false;
}
EncryptedData that = (EncryptedData) o;
...
The (!(o instanceof <yourClass>)) test will always return false if 'o'
is not an instance of <yourClass> *and* when 'o' is null.