Page 2 of 2 FirstFirst 12
Results 21 to 25 of 25
Like Tree1Likes

Thread: HashSet accept duplicated Value

  1. #21
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: HashSet accept duplicated Value

    What's the contract for equals(..) and hasnCode()?

    Does your code fulfill that contract

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

  2. #22
    vector_ever is offline Senior Member
    Join Date
    Jul 2013
    Posts
    179
    Rep Power
    2

    Default Re: HashSet accept duplicated Value

    What's the contract for equals(..) and hasnCode()?
    1- Reflexive, 2- Symmetric, 3-Transitive, 4-Consistent, 5-null comparison, 6- Equals & Hash Code relationship

    Does your code fulfill that contract
    I think it fulfills the contract...

  3. #23
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: HashSet accept duplicated Value

    *think*? Test it.

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

  4. #24
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default Re: HashSet accept duplicated Value

    Quote Originally Posted by DarrylBurke View Post
    *think*? Test it.

    db
    This here is quite important and a habit you should get into.
    If you're not sure about a bit of code you've written then construct a simple test for it.
    In this case create some Employees and ensure that those that aren't the same (in your mind) return false when compared with each other, and those that are the same (in your mind) return true. Stick some edge cases in there (eg same name, different id).
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #25
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: HashSet accept duplicated Value

    ... and while you're about that, check whether the two Employees for whom equals(...) returns true also return the same value from calling hashCode().

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

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Need Help!Duplicated IO Class
    By oszc in forum New To Java
    Replies: 1
    Last Post: 11-05-2011, 07:40 AM
  2. data get duplicated on a Vector
    By khlitoshi in forum New To Java
    Replies: 15
    Last Post: 04-05-2011, 08:44 AM
  3. ArrayList duplicated/replaced objects
    By ImAFycus in forum New To Java
    Replies: 3
    Last Post: 05-29-2010, 07:58 PM
  4. Reset form button and duplicated data
    By dbashby in forum New To Java
    Replies: 7
    Last Post: 10-10-2009, 04:40 AM
  5. XML Parsing, strange empty/duplicated Nodes
    By Singing Boyo in forum Advanced Java
    Replies: 0
    Last Post: 08-18-2009, 06:57 AM

Posting Permissions

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