Skip to content

Instantly share code, notes, and snippets.

@nrinaudo
Created November 7, 2021 13:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nrinaudo/28ec925c033769056ce4397f4160fe68 to your computer and use it in GitHub Desktop.
Save nrinaudo/28ec925c033769056ce4397f4160fe68 to your computer and use it in GitHub Desktop.
Surprising Java behaviour...
import java.util.List;
import java.util.Arrays;
import java.util.Collections;
class Demo {
static class NotComparable {}
public static void main(String[] args) {
List<NotComparable> list = Arrays.asList(new NotComparable(), new NotComparable());
Collections.sort(list, null);
// Or the following, which is equivalent:
// list.sort(null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment