[hotjoe.com] HotJoe Java Help Forums
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Visit java.com
Please send email if you are having login problems - see the posts below for more info.
Hotmail and Yahoo! users - please see the Hotmail post or the Yahoo! post for information on lost emails.
getClass() vs. Instanceof in equals()  XML
Forum Index » Java Programming
Author Message
andrew222

Newbie

Joined: 11/22/2009 14:58:13
Messages: 8
Offline

As we know there are differing opinions on what is better to use in overriding equals(). getClass() or instanceof for argument type checking.

I would like to know if there is anyone who is strongly in favor of using instanceof instead of getClass()?

This message was edited 1 time. Last update was at 02/08/2010 12:03:27

stdunbar

Newbie
[Avatar]

Joined: 06/22/2005 14:51:37
Messages: 702
Location: Superior, CO, USA
Online

I'm not sure I'm following you. I override equals() and, within there, check to make sure that I'm comparing the same type of class as the current class. I do this with instanceof. This allows derived classes to work too. If your derived class doesn't like the "parent" equals() then it should supply it's own.

Is that what you mean?

Thanks for using the forums at hotjoe.com
[WWW] [Yahoo!] [ICQ]
 
Forum Index » Java Programming
Go to:   
Powered by JForum 2.1.8 © JForum Team
This site built by Scott Dunbar of Xigole Systems. © 2005-2010 - Scott Dunbar
Java and the Java Get Powered logo are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries.
hotjoe.com and xigole.com have no affiliation with Sun Microsystems, Inc.