[concurrency-interest] Re: AtomicInteger and AtomicLong should implement Number
Wed, 7 Jan 2004 08:31:23 +0000
Doug Lea wrote,
> Note in particular that AtomicInteger cannot be a Number because it
> would break the hashcode contract. And it would not have a symmetric
> equals method.
> (Also note that AtomicReference is not a java.lang.ref.Reference.)
It might be helpful to note that AtomicReference<T> doesn't extend T. T
isn't a supertype of AtomicReference<T> because Ts are values and
AtomicReference<T>s are references to values, and values and references
to values have fundamentally different characteristics. And since
AtomicReference<T> doesn't extend T there's no reason to expect it to
extend any supertype of T other than Object either.
The analogy then is that AtomicInteger is roughly logically equivalent
to AtomicReference<Integer> hence it's not an Integer, in which case
there's no reason to suppose it's a Number either.
Maybe it'd reduce confusion (at the cost of keystrokes) to rename
AtomicInteger et al to AtomicIntegerReference?