title: ConcurrentMap.compute used as remove
body: <p>With Java 8, I am implementing a wrapper on <code>java.util.concurrent.ConcurrentMap</code> interface, particularly the <code>remove(Object key)</code> method. Since I need to do more checks during the remove, I need to implement the functionality using </p>
  
  <p><code>compute(K key, BiFunction&lt;? super K, ? super V, ? extends V&gt; remappingFunction)</code></p>
  
  <p>However, here the problem is: I have to accept <code>Object</code> but pass that to <code>compute</code> as <code>K</code>. With generics, I even can't do a runtime check like <code>if (key instanceof K) ...</code></p>
  
  <p>I understand why the signature for <code>compute</code> was chosen this way; if it was just <code>Object</code>, in case that compute needs to create a new entry, it could not simply use the key. But I am not sure how to resolve this - is there any recommended pattern but use multiple calls as below?</p>
  
  <pre><code>for (;;) {
      V v = map.get();
      if (check(k, v)) {
          if (map.remove(k, v)) return true;
      } else return false;
  }
  </code></pre>
  
  <p>Thanks</p>