title: Java: howto write equals() shorter
body: <p>I get headaches when I have to write nearly 10 lines of code to say <code>2 Objects are equal, when their type is equal and both's attribute is equal</code>. You can easily see that in this way of writing the number of lines increase drastically with your number of attributes.</p>
  
  <pre><code>public class Id implements Node {
  
          private String name;
  
          public Id(String name) {
                  this.name = name;
          }
  
          public boolean equals(Object o) {
                  if (o == null)
                          return false;
                  if (null == (Id) o)
                          return false;
                  Id i = (Id) o;
                  if ((this.name != null &amp;&amp; i.name == null) || (this.name == null &amp;&amp; i.name != null))
                          return false;
                  return (this.name == null &amp;&amp; i.name == null) || this.name.equals(i.name);
          }
  
  }
  </code></pre>