Hello! I have an interesting problem with the following code. Whenever I try to run this program it gives me false(No!) for (date.equals(date2)) method even though it should return true(Yes!). I tried to figure out the fault using debugger but could not succeded. Can anyone please help me?
Mahi.
EDIT by mw: Added Code Tags. [ February 16, 2007: Message edited by: marc weber ]
Your date is a reference of type Date. But your date1, date2, and date3 are all of type Object.
You've overloaded the equals method to take a Date object, but when you call it using an Object as an argument, the equals method inherited from Object is invoked. (Remember, calls to overloaded methods are resolved based on the arguments' reference types -- not their true runtime types. This is different than overridden method calls, which are resolved based on the calling object's true runtime type.) [ February 16, 2007: Message edited by: marc weber ]
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org