Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

All the overriden equals!

 
Marcela Blei
Ranch Hand
Posts: 477
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Marcela Blei
Ranch Hand
Posts: 477
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 477
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic