Author | Topic: equals |
shan unregistered |
posted February 19, 2000 07:38 PM
For equals to work should both objects be of same type??? why is Equals on wrapper class always giving --false Is it i did'nt try any correct examples are my Question is wrong
|
maha anna bartender |
posted February 19, 2000 08:54 PM
whenever you get doubts like this you refer to JDK API Doc. From the API for the Wrapper classes(Boolean/Byte/Integer..) ------------ public boolean equals(Object obj) Compares this object to the specified object. Parameters: obj - the object to compare with Returns: true if the objects are the same; false otherwise. Overrides: equals in class Object
|
Tony Alicea sheriff |
posted February 20, 2000 08:20 AM
When you override equals you define the term of equality although I am not sure you should be careless since I understand that certain rules like of associativity, commutativity etc. should also be met.
|
maha anna bartender |
posted February 20, 2000 11:59 AM
Tony has got a point. It we OVERRIDE the .equals(Object o) method then we have define the hashCode() also. This method should return the same value for objects that compare equality using this equals(Object o) method. maha anna
|
Tony Alicea sheriff |
posted February 20, 2000 12:39 PM
Thanks maha anna; I forgot about the part of the hashCode() !
|
| | |