Summary: | [hashcode/equals] Suggestion for shorter Equals | ||
---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | William Voorsluys <williamvoor> |
Component: | UI | Assignee: | JDT-UI-Inbox <jdt-ui-inbox> |
Status: | NEW --- | QA Contact: | |
Severity: | enhancement | ||
Priority: | P3 | ||
Version: | 3.2.1 | ||
Target Milestone: | --- | ||
Hardware: | PC | ||
OS: | Linux | ||
Whiteboard: |
Description
William Voorsluys
2006-12-08 18:13:08 EST
Moving to JDT/UI You can make it even shorter than that using a collection of 'and' combinators: AnyClass other = (obj instanceof AnyClass ? (AnyClass)obj : null ); return this == obj || ( obj != null && getClass() == obj.getClass() && !(this.field1 == null ? other.field1 == null : this.field1(equals(other.field1)) && !(this.field2 == null ? other.field2 == null : this.field2(equals(other.field2)) && ); i'm not sure how either the formatter would handle this, or the average programmer reading it, either. It would also be interesting to see (from a compiled approach) which one is better, or whether it makes any significant difference.. Alex. |