design - Why does the java.util.Set<V> interface not provide a get(Object o) method? -
i understand 1 instance of object according .equals() allowed in set , shouldn't "need to" object set if have equivalent object, still have .get() method returns actual instance of object in set (or null) given equivalent object parameter.
any ideas/theories why designed this?
i have hack around using map , making key , value same, or that.
edit: don't think people understand question far. want exact object instance in set, not possibly different object instance .equals() returns true.
as why want behavior, typically .equals() not take account properties of object. want provide dummy lookup object , actual object instance in set.
while purity argument make method get(object)
suspect, underlying intent not moot.
there various class , interface families redefine equals(object)
. 1 need no further collections interfaces. example, arraylist , linkedlist can equal; respective contents merely need same , in same order.
consequently, there reasons finding matching element in set. perhaps clearer way of indicating intent have method like
public interface collection<e> extends ... { ... public e findmatch(object o) throws unsupportedoperationexception; ... }
note api has value broader within set.
as question itself, don't have theory why such operation omitted. minimal spanning set argument not hold, because many operations defined in collections apis motivated convenience , efficiency.
Comments
Post a Comment