All the non-inherited public methods are final except for toString(),
intValue(), longValue(), floatValue(), and doubleValue(), which are all
simple wrappers around calls to get().
I don't know the specific reason for the use of final. However, even if
they were not final, I would not override any of the get or set methods
unless I were going to override all of them, in which case I would
effectively have a new class. In order to work correctly they all have
to be implemented using the same underlying mechanism.
Patricia
Thanks to you all for all your explanations.
My specific requirement was to maintain some sort of statistics (e.g.
min, max, average) of values taken on by an AtomicInteger. I also
wanted to do this without modifying code to use another wrapper class.
My intention was to use aspectj to intercept AtomicInteger variable
initializations and inject an overridden class instead where I would
do these additional calculations before calling super class methods to
pass on the call to the real AtomicInteger class. This is however not
possible now because AtomicInteger methods are final.
If the intention behind final declarations was just to ensure the
atomicity of the atomic operations, it could also have been done by
not giving access to the underlying fields to outside packages. Or, am
I missing something here?
Since I did not have any other alternative, I have now created my own
wrapper classes around Java's Atomic... classes. The wrappers have the
exact same methods as the real Atomic... classes and contain an
instance of the real Atomic... class to do the job. I had no other
option but to go and modify my sources, but I maintained the same
class names so that I had to update only the import statements.
- tan