Is Collections.sort(List) still stable (java 8, 9..)?

Paul Sandoz paul.sandoz at oracle.com
Thu Nov 16 17:56:00 UTC 2017



> On 16 Nov 2017, at 09:28, Piotr Findeisen <piotr.findeisen at gmail.com> wrote:
> 
> Hi Paul,
> 
> I think this is also how it looks like in Java 8

Yes.


> (but I also checked docs & code in 9 before posting).

Ok.


> Basically, in List.sort docs, the word "stable" is @implNote for *default implementation*, not a contract that a subclass implementor must obey.
> At least I understand this that way.
> 

Yes.


> Thus, for List not having specialised sort implementation, Collections.sort(List) will be stable sort.
> For a List that has specialised sort implementation (that happens not to be stable),  Collections.sort(List)  will not be stable as well, even though javadoc expressly promises that.
> 

Agreed, we need to specify the stability on List.sort (as we do for ordered streams on Stream.sorted).

I logged this issue:

  https://bugs.openjdk.java.net/browse/JDK-8191429 <https://bugs.openjdk.java.net/browse/JDK-8191429>

Thanks for reporting this,
Paul.


More information about the core-libs-dev mailing list