R
Red Orchid
The following code is a part of java.util.Map<K,V> :
<code_#1>
V put(K key, V value);
V get(Object key);
V remove(Object key);
boolean containsKey(Object key);
</code_#1>
The above code allows this:
--
HashMap<K, V> map = ....;
V val = ....;
....
map.remove(val); // # 2
--
#2 seems useless and prone to bugs.
What is the advantage of 'code_#1 over the following code?
<code>
V get(K key);
V remove(K key);
boolean containsKey(K key);
</code>
Thanks.
<code_#1>
V put(K key, V value);
V get(Object key);
V remove(Object key);
boolean containsKey(Object key);
</code_#1>
The above code allows this:
--
HashMap<K, V> map = ....;
V val = ....;
....
map.remove(val); // # 2
--
#2 seems useless and prone to bugs.
What is the advantage of 'code_#1 over the following code?
<code>
V get(K key);
V remove(K key);
boolean containsKey(K key);
</code>
Thanks.