title: How can I sort a list with different objects that implement the same interface?
body: <p>I have an abstract class:</p>
  
  <pre><code>public abstract class Employee implements Comparable&lt;Employee&gt;{
    public Double getSalary();
  
  
      @Override
      public Double compareTo(final Employee employee2) {
      }
  }
  </code></pre>
  
  <p>Two classes that extends this abstract class:</p>
  
  <pre><code>public class Manager {
    public Double getSalary(){}
  }
  
  public class Chef{
    public Double getSalary(){}
  }
  </code></pre>
  
  <p>I want to sort it so that all the Chef objects in the list are in the front, then after all the Chef objects I want the Manager objects to be sorted in descending order with the highest salary first. In other words, for Chef objects, I only want them to be pushed to the front of the list, nothing else. For the Manager object I want them to be sorted by salary and to be put at the end of the list after the Chef objects. </p>
  
  <p>e.g</p>
  
  <pre><code>Manager manager1 = new Manager(40000);
  Manager manager2 = new Manager(50000);
  Manager manager3 = new Manager(60000);
  Chef chef1 = new Chef(25000);
  Chef chef2 = new Chef(25500);
  Chef chef3 = new Chef(28000);
  Chef chef4 = new Chef(29000);
  List&lt;Employee&gt; employees = new ArrayList&lt;Employee&gt;();
  employees.add(manager3);
  employees.add(manager1);
  employees.add(chef1);
  employees.add(chef3);
  employees.add(manager2);
  employees.add(chef4);
  employees.add(chef2);
  </code></pre>
  
  <p>After sorting the elements in the list could be like so:</p>
  
  <pre><code>0. chef1 = 25000 // Chef objects pushed to front but not sorted by salary
  1. chef3 = 28000
  2. chef4 = 29000
  3. chef2 = 25500
  4. manager3 = 60000 // Manager objects pushed to the back and sorted by salary
  5. manager2 = 50000
  6. manager1 = 40000
  </code></pre>
  
  <p>My compareTo method:</p>
  
  <pre><code>@Override
  public int compareTo(final Employee employee2) {
      if (this instanceof Manager|| employee2instanceof Manager) {
          return employee2.getSalary().compareTo(this.getSalary());
      }
  
      return -1;
  }
  </code></pre>
  
  <p>However, this brings the Manager objects to the front. I'm confused on how to work with the Chef object in this compareTo method.   </p>