I'm trying to sort a list of objects, by a property of that object. For example a list called "persons", object called "person" and some properties like "age", "length" and "motherlanguage". I want to sort this list by either age, length or motherlanguage. Normally you would do this as followed:
public class PersonComparator implements Comparator<Person> {
@Override
public int compare(Person person1, Person person2) {
return person1.getName().compareTo(person2.getName());
}
}
Collections.sort(persons, new PersonComparator());
Problem is, the list of properties is quite long so making a comparator for each property in 'Android' java is too much work (it's doable, but i'm lazy), so I want to a comparator with reflection. In java this is called a bean comparator but i don't know how i can implement something like this in 'Android' java.