directory-kerby mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Zheng, Kai" <kai.zh...@intel.com>
Subject RE: eqlas() method
Date Fri, 08 Jan 2016 22:42:24 GMT
OK. Sounds good. I guess my IDE should be upgraded so it will can generate the better codes
...

-----Original Message-----
From: Emmanuel L├ęcharny [mailto:elecharny@gmail.com] 
Sent: Saturday, January 09, 2016 2:59 AM
To: kerby@directory.apache.org
Subject: eqlas() method

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.



Mime
View raw message