I'm putting objects into a LinkedHashSet, and I don't want any duplicate objects added (i.e. object with same data, not necessary exact same object).
From what I've read, LinkedHashSet should prevent duplicate objects from being added (if I'm wrong, just let me know).
I'm guessing LinkedHashSet<T> uses either T.equals() or T.hashCode() (or maybe both?) to determine whether the new T that you're adding is unique; so I tried overriding those 2 functions:
However, I'm getting an error with my equals() function. I see that Object.equals() takes an Object parameter instead of a generic T parameter. Does anyone know why they didn't genericize equals() when they added generics?
Do I need to take an Object instead and just cast it, or will it work fine the way it is (once I take out the @Override annotation)?
From what I've read, LinkedHashSet should prevent duplicate objects from being added (if I'm wrong, just let me know).
I'm guessing LinkedHashSet<T> uses either T.equals() or T.hashCode() (or maybe both?) to determine whether the new T that you're adding is unique; so I tried overriding those 2 functions:
Code:
public class UserINIData
{
public String UserID;
...
@Override
public boolean equals( [b]UserINIData[/b] rhs ) // Error
{
return UserID.equals( rhs.UserID );
}
@Override
public int hashCode()
{
return UserID.hashCode();
}
}
Do I need to take an Object instead and just cast it, or will it work fine the way it is (once I take out the @Override annotation)?