Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 2nd, 2008, 12:58 AM   #1
fhslacrosse13
Newbie
 
Join Date: Oct 2006
Posts: 25
Rep Power: 0 fhslacrosse13 is on a distinguished road
Generic type + equals() method

I'm doing a program for my Data Structures class but I've ran into a little problem with my code that I can't seem to figure out. I have to override the toString(), equals(), and compareTo() methods all with generic type and I have everything working except equals().
public boolean equals(T other)
    {        
        Customer eOther = (Customer)other;
        if(id.equals(eOther.id))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
I get a compiling error that says that I have declared two methods with the same name and is only allowed if one overrides the other. If I change equals() around to be for the Customer class that I am writing it works just fine...I have no clue what I'm doing incorrectly. I don't have the book for the class so I have no notes on this stuff. Any help is much appreciated.
fhslacrosse13 is offline   Reply With Quote
Old Jun 2nd, 2008, 1:04 AM   #2
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 856
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Re: Generic type + equals() method

public boolean equals(Object obj) {
    if (!(object instanceof Customer))
        return false;
    Customer cust = (Customer)obj;
    // determine if cust is equal to this
    ...
}
titaniumdecoy is offline   Reply With Quote
Old Jun 2nd, 2008, 1:22 PM   #3
fhslacrosse13
Newbie
 
Join Date: Oct 2006
Posts: 25
Rep Power: 0 fhslacrosse13 is on a distinguished road
Re: Generic type + equals() method

Thanks
fhslacrosse13 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Method not returning string csrocker101 C# 1 Apr 6th, 2007 6:45 PM
How to invoke static method from a Class object? smith.norton Java 1 Oct 5th, 2006 3:00 AM
Arrays with Generic Type azurik Java 6 Jun 14th, 2006 12:31 PM
Pointer return type,.. ??? Mack1982 C++ 28 May 26th, 2006 8:02 PM
Debug recursion method() pr0gm3r Java 3 Oct 11th, 2005 12:33 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:32 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC