Results 1 to 2 of 2
  1. #1
    skyineyes is offline Member
    Join Date
    May 2008
    Posts
    3
    Rep Power
    0

    Default Why Equals method should be over ridden in Hashcode?

    Hi

    I am not understanding that why Equals method needs to be overridden for use in Hashcode ?:confused: :mad::confused:

    Can anybody give a very very basic code example to make it clear...

    a) example not using overridden equals method ... with dis-advantage
    b) example using overridden equals method and hashcode method

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    I am not understanding that why Equals method needs to be overridden for use in Hashcode ?
    Who asked you about that?

    reimplementing it through hascode is like,

    Get the hashcode for the String1 to be compared (an int)
    Get the hashcode for the String2 (will be compared) (an int)...

    equate them, if they are equal, then return true, otherwise false.

    The advantage is that, whenever they came from different instances, they could still be compared.

    Try to browse the code for equals method(under the class that will be overriden) and see how it is implemented....
    you can find it in (im not sure) it's a zip file named src that can be found in jdk folder.

    ....Just to eliminate confusions....
    freedom exists in the world of ideas

Similar Threads

  1. Replies: 2
    Last Post: 03-26-2010, 05:12 PM
  2. cannot call private method from static method
    By jon80 in forum New To Java
    Replies: 3
    Last Post: 05-07-2008, 08:37 AM
  3. Replies: 1
    Last Post: 04-17-2008, 10:10 PM
  4. Replies: 0
    Last Post: 01-25-2008, 11:13 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
  •