Created
December 18, 2012 17:17
-
-
Save rentalcustard/4329899 to your computer and use it in GitHub Desktop.
Example of using an anonymous comparator class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public List<Foo> sort(List<Foo> foos) { | |
return Collections.sort(foos, new Comparator<Foo>() { | |
@Override | |
public int compare(Foo a, Foo b) { | |
//comparison logic | |
} | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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