So I have a list of objects, specifically a list of vehicles, that contains cars, motos and bicicles. Each one of this objects has different atributes (car and moto have max velocity while bicicle doesn´t for instance.)
Moto Bicicle and Car are subclasses of Vehicle and Vehicle implements the interface Comparable.
They do have on thing in common, the year when they were made and that's how I wanted to sort my array, using that specific attribute. By default java is sorting based on another attribute the objects have in common which is "color".
This is the code used to sort the arrays.(It has to be this one)
public static <T> void sortArray(Comparable<T>[] a) {
Arrays.sort(a);
}
Is there a way to select the attribute which I would like to use to sort the list? Thanks for the help in advance.