(This is a hypothetical question for discussion, I have no real problem).
Say I'm doing an implementation of SortedSet by extending LinkedHashMap :
class LinkedHashSortedMapThing extends LinkedHashMap implements SortedSet { ... }
Now programmers who use this class can execute
LinkedHashMap x = new LinkedHashSortedMapThing();
But what if I consider the LinkedHashMap extension LinkedHashMap details and do not want this to be part of the class contract? If people use the line above, I can no longer freely modify this detail without worrying about breaking the existing code. Is there a way to prevent such things besides preferring composition over inheritance (which is not always possible due to private / protected members)?
source share