I have a class implementing a data structure storing Comparable objects. Some instances hold Longs and other Strings.
I want to count the number of comparisons that occur, without changing the data structure class or the application too much.
One natural idea is to implement a new class (say MyLong) whose compareTo() increments some statistics counter and then calls the real compareTo(). Then change the app to store MyLongs instead of Longs, etc. This doesn't work because I can't inherit from Long or String.
Can this approach be made to work? Is there another way of accomplishing this goal?