| Author |
All the overriden equals!
|
Marcela Blei
Ranch Hand
Joined: Jun 28, 2000
Posts: 477
|
|
Is there any equals method in all the API specification that throws an exception when you pass to it an object that isn�t an instanceof the type object that the equals belongs to. Eg. I began to read the API doc by it�s index and I didn�t find any exception thrown so, because it�s a tedius job, perhaps someone know a special case when this happens. Thanks.
|
 |
Ajith Kallambella
Sheriff
Joined: Mar 17, 2000
Posts: 5782
|
|
Marcela, No need to work that hard. Use rules of overriding. Since the method on the Object is not declared to be throwing any exceptions, even the overridden versions cannot! Ajith
|
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
|
 |
Marcela Blei
Ranch Hand
Joined: Jun 28, 2000
Posts: 477
|
|
But they can throw a ClassCastException that is a Runtime Exception if the implemented equals try to cast the object argument directly without using the instanceof operator before. [This message has been edited by Marcela Blei (edited August 01, 2000).]
|
 |
Ajith Kallambella
Sheriff
Joined: Mar 17, 2000
Posts: 5782
|
|
Marcela, It is not necessary to declare RuntimeException and its subclasses in the method signature. They can be ( and usually ) are thrown without declaring them. Hence they don't appear as a part of method signature in the API documentation. Ajith
|
 |
Marcela Blei
Ranch Hand
Joined: Jun 28, 2000
Posts: 477
|
|
Sorry, my question wasn�t clear. Suppose the following question: What�s the result of compiling and executing the following code: a) It prints false and throws a ClassCastException b) It throws a ClassCastException c) It prints false false
|
 |
thomas
Ranch Hand
Joined: May 26, 2002
Posts: 79
|
|
|
As far as I can see, the equals() methods in the API simply return false if the objects are unrelated. They do not throw an exception.
|
 |
 |
|
|
subject: All the overriden equals!
|
|
|