The Artima Developer Community
Sponsored Link

Practical pattern regarding equals()

Advertisement

Advertisement

This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Practical pattern regarding equals()

Posted by Vjekoslav Nesek on 16 Sep 1998, 7:30 AM

You can make your code more elegant and gain some perfomance
improvements by implementing equals in a following manner:

class A {

/* ... */

public boolean equals(A a) {
/* ... */
}

public boolean equals(Object o) {
return o instanceof A? equals((A) o) : false;
}
}




Replies:
  • equals() C. Wortz 05 Oct 1998, 6:39 AM (0)

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us