[concurrency-interest] Minor generics nit in AtomicReferenceArray

Martin Buchholz martinrb at google.com
Thu Mar 26 18:31:08 EDT 2009


One difference between collections and Atomic* is that the Atomic classes
operate on object identity comparisons, not on .equals() method invocations.
So if the type parameter E is accurate, expect must be an E.

Martin

On Thu, Mar 26, 2009 at 14:26, David M. Lloyd <david.lloyd at redhat.com> wrote:
> 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);
>     }
>
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>



More information about the Concurrency-interest mailing list