I'm trying to implement LinkedList and I've come across a few
optimisations which it seems to me *should* be considered compatible
(the only case where they'd give a user different results is with
reflection) but I want to check. Which of the following are legal:

~ Not overriding a superclass method when the spec says it is overridden
(for
  cases where I consider that the tiny efficiency gain isn't worth the
big
  increase in code size)?
~ Overriding a superclass method (for efficiency) when the spec says it
is not
  overridden?
~ Adding a package-private superclass in between a class and its specced
  superclass (for cases where code can be reused)?

All of these things seem to me to be implementation issues, and they are
not explicitly described in the spec. However, the javadoc does include
this information, by including information about which methods are
inherited from the superclass and which are not, even where the
overridden methods are specced to *do* the exact same thing as their
superclass methods.

The first one isn't really important as you can always override a method
to just call super.whatever() (although it does increase the number of
methods that need to be redundantly doc-commented). The second makes a
big difference to me as I've found a case in LinkedList where I can make
several methods that would be O(n) into O(1) (and they aren't methods
that have the implementation precisely specced, so I do have the freedom
to make that choice, as long as it's compatible). The third one could
remove about a quarter of my code and reduce the number of inner classes
too, as well as slightly improving efficiency.

My personal opinion is that all of these changes dang well should be
legal, but I don't know where to look to find out whether they actually
*are*... can anyone help?

TIA,
Stuart.

Reply via email to