Skip to content

Instantly share code, notes, and snippets.

@rentalcustard
Created December 18, 2012 17:17
Show Gist options
  • Save rentalcustard/4329899 to your computer and use it in GitHub Desktop.
Save rentalcustard/4329899 to your computer and use it in GitHub Desktop.
Example of using an anonymous comparator class
public List<Foo> sort(List<Foo> foos) {
return Collections.sort(foos, new Comparator<Foo>() {
@Override
public int compare(Foo a, Foo b) {
//comparison logic
}
});
}
public List<Foo> foosSortedByRange(List<Foo> foos, final Env env) {
return Collections.sort(foos, new Comparator<Foo>() {
@Override
public int compare(Foo a, Foo b) {
return a.range(env).compareTo(b.range(env));
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment