G
GeorgeH
Hello!
I have a following situation:
A class with members
public class Item
{
Integer id;
String value:
....
}
I store instances of this Item class into ArrayList.
Item class has also a equals method for Collection.contains method.
In equals method I check that instance type is ok and that values
of id and value are same than reference object's .
BUT, sometimes I only need equals method that would
check only if id member variable is same, not value member.
I can't write two equals methods to Item class so, what could
be a practical way to check if ArrayList has Item class instance that has
same id that I'm searching, but value member would then be ignored?
I try avoid loops and then checking each Item objects id member.
But how to implement this, any tips?
Cheers!
I have a following situation:
A class with members
public class Item
{
Integer id;
String value:
....
}
I store instances of this Item class into ArrayList.
Item class has also a equals method for Collection.contains method.
In equals method I check that instance type is ok and that values
of id and value are same than reference object's .
BUT, sometimes I only need equals method that would
check only if id member variable is same, not value member.
I can't write two equals methods to Item class so, what could
be a practical way to check if ArrayList has Item class instance that has
same id that I'm searching, but value member would then be ignored?
I try avoid loops and then checking each Item objects id member.
But how to implement this, any tips?
Cheers!