[concurrency-interest] Minor generics nit in AtomicReferenceArray

David M. Lloyd david.lloyd at redhat.com
Thu Mar 26 17:26:23 EDT 2009


It would be nice if the "expect" parameter of the two compareAndSet methods 
in AtomicReferenceArray would be declared as "Object" rather than "E". 
It's sometimes the case that the expect value is of an unknown class, and 
this fact doesn't affect operation of the method in any way, yet one still 
must annoyingly cast the parameter.

Here's a patch which illustrates the change.  As far as I'm aware, this 
won't affect compatibilty in any way.

- DML

diff -r dde3fe2e8164 
src/share/classes/java/util/concurrent/atomic/AtomicReferenceArray.java
--- 
a/src/share/classes/java/util/concurrent/atomic/AtomicReferenceArray.java 
Wed Feb 25 14:32:01 2009 +0000
+++ 
b/src/share/classes/java/util/concurrent/atomic/AtomicReferenceArray.java 
Thu Mar 26 16:18:34 2009 -0500
@@ -159,7 +159,7 @@
       * @return true if successful. False return indicates that
       * the actual value was not equal to the expected value.
       */
-    public final boolean compareAndSet(int i, E expect, E update) {
+    public final boolean compareAndSet(int i, Object expect, E update) {
          return unsafe.compareAndSwapObject(array, rawIndex(i),
                                           expect, update);
      }
@@ -177,7 +177,7 @@
       * @param update the new value
       * @return true if successful.
       */
-    public final boolean weakCompareAndSet(int i, E expect, E update) {
+    public final boolean weakCompareAndSet(int i, Object expect, E update) {
          return compareAndSet(i, expect, update);
      }




More information about the Concurrency-interest mailing list