The literal answer is that apply() implemented in terms of ++ , which is defined in a SortedSet , and therefore returns a SortedSet . ++ then uses + , which is defined in a TreeSet , so you can return it to a TreeSet if it is critical (although I would not recommend it, as it depends on the implementation and may change over time!).
What do you need from a TreeSet that you cannot get from a SortedSet?
I'm not sure what is the rationale for the design decision, although it seems like it has changed in 2.8.
Kristian domagala
source share