Note that there are some explanatory texts on larger screens.

plurals
  1. POAutomatically generating equals and hashCode in Eclipse that is aware of @NonNull annotations
    text
    copied!<p>Is there a way to configure Eclipse to automatically generate <code>hashCode</code> and <code>equals</code> with awareness of <code>@NonNull</code> annotations? Currently my Eclipse generates the code with unnecessary <code>null</code> checks, even on fields that are marked <code>@NonNull</code>.</p> <hr> <p>Note that FindBugs will raise warnings that <a href="http://findbugs.sourceforge.net/bugDescriptions.html#RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE" rel="nofollow noreferrer">these null checks are redundant</a>. Of course we can add <code>@edu.umd.cs.findbugs.annotations.SuppressWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")</code> to the methods, but that seems to undermine the role of FindBugs and <code>@NonNull</code> in the first place.</p> <p>It looks to me that the best solution is to have Eclipse be aware of JSR 305 and generate <code>equals</code> and <code>hashCode</code> accordingly without <code>null</code> checks (and if they are <code>null</code> anyway then so be it and let a <code>NullPointerException</code> be thrown naturally, because a contract violation has occurred).</p> <p>Short of that, having a way to customize the <code>equals</code> and <code>hashCode</code> template generated by Eclipse would also be nice.</p> <h3>Related questions</h3> <ul> <li><a href="https://stackoverflow.com/questions/802825/make-eclipse-equals-hashcode-use-getters">make Eclipse equals() / hashCode() use getters </a></li> <li><a href="https://stackoverflow.com/questions/281121/is-it-possible-to-make-eclipse-generate-hashcode-and-equals-with-hashcodebuilder">Is it possible to make eclipse generate hashCode and equals with HashCodeBuilder and EqualsBuilder </a></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload