[concurrency-interest] Minor generics nit in AtomicReferenceArray

Kevin Bourrillion kevinb at google.com
Thu Mar 26 18:01:37 EDT 2009


Interesting.  I'll just note that the standard set by the Collections
Framework agrees with you:  only parameters which might cause harm are
restricted to E, never the innocuous ones.  Some, for example Bill Pugh,
disagree with this, saying that because it's so rare to need to query with a
non-E, the benefits of supporting that scenario are fewer than those of
catching more bugs in the usual use cases.



On Thu, Mar 26, 2009 at 2:26 PM, 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
>



-- 
Kevin Bourrillion @ Google
internal:  http://go/javalibraries
google-collections.googlecode.com
google-guice.googlecode.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20090326/74d408ae/attachment.html>


More information about the Concurrency-interest mailing list