Results 1 to 9 of 9
  1. #1
    voipp is offline Member
    Join Date
    Oct 2013
    Posts
    51
    Rep Power
    0

    Exclamation hashCode function conflict

    It says hashCode must keep returning the same value for non modified object. But the standart hash algorithm based on random numbers returns different values.Why?
    And one more similar question, custom classes i use, contains function equals , that doesnt use hashCode to compare objects. It only used in hash maps. Why its not neccesary just to compare objects by its hash code, its much nore simplier than anithing else.

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,385
    Blog Entries
    7
    Rep Power
    20

    Default Re: hashCode function conflict

    Quote Originally Posted by voipp View Post
    But the standart hash algorithm based on random numbers returns different values.Why?
    Page and paragraph please; none of the correctly implemented hashCode() methods do that.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,863
    Rep Power
    19

    Default Re: hashCode function conflict

    You'll have to give us some code that shows the hash value changing for an unmodified object, because I suspect you are wrong.

    I'm not too sure what you're asking for the second bit, but it sounds like you think a hashcode is sufficient to determine if two objects are equal?
    In which case I would point out that a hashing algorithm does not guarantee uniqueness.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,423
    Rep Power
    5

    Default Re: hashCode function conflict

    Quote Originally Posted by voipp View Post
    Why its not neccesary just to compare objects by its hash code, its much nore simplier than anithing else.
    A hash code is some value based on information from an object which can be used to categorize or group the object with other similar objects. By similar, I mean that have the same hash code. So the last 4 digits of a phone number is a legitimate (but not necessarily good) hash code. Yet the phone numbers in that group could still be different.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  5. #5
    voipp is offline Member
    Join Date
    Oct 2013
    Posts
    51
    Rep Power
    0

    Default Re: hashCode function conflict

    You mean because of collisions , objects with equal hash code could not be compared by equals() function ?

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,773
    Rep Power
    5

    Default Re: hashCode function conflict

    I don't know how you get that from what Jim said.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    voipp is offline Member
    Join Date
    Oct 2013
    Posts
    51
    Rep Power
    0

    Default Re: hashCode function conflict

    from this phrase -
    A hash code is some value based on information from an object which can be used to categorize or group the object with other similar objects. By similar, I mean that have the same hash code
    Perhaps , someone ought to speak more clearly. English is not my mother tongue, so , please keep answering more clearly or write your posts in Russian

  8. #8
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,423
    Rep Power
    5

    Default Re: hashCode function conflict

    Quote Originally Posted by voipp View Post
    You mean because of collisions , objects with equal hash code could not be compared by equals() function ?
    No. Collisions are irrelevant in this case. The rules are that two objects which have the same hashCode may or may not be equal as determined by the
    equals() method. But if the objects are equal as determine by the equals() method, then the hashCodes must be the same. Otherwise, the objects won't play well with maps.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  9. #9
    voipp is offline Member
    Join Date
    Oct 2013
    Posts
    51
    Rep Power
    0

Similar Threads

  1. serializable and externalizable flags conflict
    By anoorally in forum New To Java
    Replies: 0
    Last Post: 03-16-2012, 04:00 PM
  2. Filter url pattern conflict in web.xml
    By hemant_metalia in forum Advanced Java
    Replies: 0
    Last Post: 11-07-2011, 10:14 AM
  3. Inner class name conflict problem
    By ggyyree in forum New To Java
    Replies: 1
    Last Post: 12-10-2010, 09:10 PM
  4. Name Conflict
    By vanhuh21 in forum New To Java
    Replies: 7
    Last Post: 08-09-2010, 11:45 AM
  5. jdk jre tomcat conflict
    By simo_mon in forum Java Servlet
    Replies: 7
    Last Post: 09-29-2009, 08:44 AM

Tags for this Thread

Posting Permissions

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