I have a Set of expensive objects.
These objects have IDs and the equals uses these IDs for equality.
These objects’ type has two constructors; one for the expensive object, and one that just sets the ID.
So I can check if a particular ID is in the Set using Set.contains(new Object(ID)).
However, having determined the object is in the set, I cannot get the object instance in the set.
How can I get the exact object that the set contains?
Consider using the
UnifiedSetclass in Eclipse Collections. It implements thePoolinterface in addition toSet.PooladdsMap-like API for put and get.Poolis more memory efficient thanMapsince it doesn’t reserve memory for values, only keys.Note: I am a committer for Eclipse Collections.