// NormalList<Person> personen = new ArrayList<>();
...
Collections.sort(personen, new Comparator<Person>() {
@Override
public int compare(Person x, Person y) {
return x.getAlter().compareTo(y.getAlter());
}
});
// Lambda
personen.sort((x,y) -> x.getAlter().compareTo(y.getAlter()));Code-Sprache:PHP(php)
// Interface mit anonymer Implementierung// Die Annotation ist eigentlich nur informativ – es funktioniert auch ohne.
@FunctionalInterface
publicinterfaceComparator<T> {
...
int compare(T o1, T o2);
...
boolean equals(Object obj);Code-Sprache:PHP(php)