Results 1 to 4 of 4
  1. #1
    gberisha is offline Member
    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Question Correctly Implementing the equals method

    Hi there,
    I'm a java starter - who is really desperate for a little help .
    My question goes as follows :

    ex. public class Something {
    private int attribute;
    public boolean equals(Something other) {
    if (other == null) { return false; }
    if (other == this) { return true; }
    if (other.attribute == this.attribute) { return true; }
    return false;
    }
    }

    what functional Problems will occur if i use the Code above?

    Thanks in advance.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,888
    Rep Power
    20

    Default Re: Correctly Implementing the equals method

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    gberisha is offline Member
    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Default Re: Correctly Implementing the equals method

    Quote Originally Posted by DarrylBurke View Post
    Read it all, sadly it was no help
    please if someone could just explain to me what's wrong with the code

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,017
    Blog Entries
    7
    Rep Power
    23

    Default Re: Correctly Implementing the equals method

    Did you read closely enough? In the Object class the signature of the method is: public boolean(Object other); <-- hint.

    kind regards,

    Jos
    I have the stamina of a seal; I lie on the beach instead of running on it.

Similar Threads

  1. What is the use of equals () method?
    By srinivasmallabathula in forum Advanced Java
    Replies: 3
    Last Post: 08-04-2011, 05:57 PM
  2. equals method :::::HELP:::::
    By alihht in forum New To Java
    Replies: 5
    Last Post: 03-09-2010, 08:19 AM
  3. ArrayLists compareTo method, equals method
    By random0munky in forum New To Java
    Replies: 2
    Last Post: 10-26-2009, 08:20 PM
  4. equals method
    By mani_miit in forum Advanced Java
    Replies: 7
    Last Post: 09-09-2009, 10:26 PM
  5. equals method
    By timkd127 in forum New To Java
    Replies: 2
    Last Post: 01-24-2009, 07:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •