You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@netbeans.apache.org by Owen Thomas <ow...@gmail.com> on 2019/07/25 08:16:27 UTC

Rationale for "equals() method not checking type of its parameter".

I want to override the equals method of a common ancestor class so it will
compare two subtypes for equality regardless of what subtype they are. I
noticed that when I replace this code:

        if (getClass() != obj.getClass()) {
            return false;
        }
        final Referent<S,C_IN,_C,I>other = (Referent<S,C_IN,_C,I>) obj;

With this code:

        Referent<S,C_IN,_C,I>other;
        try{
            other=(Referent<S,C_IN,_C,I>) obj;
        }catch(ClassCastException x){return false;}

However, I get the warning in the title of this email.

I don't think this warning is correct. Who is right; me or NB 11?

Thanks,

  Owen.