title: How does a static method use a comparator?
body: <p>I have a static method which needs to invoke the <code>SportsMenComparator</code>. But this, as we all know is not allowed. How does a static function use a comparator subclass ? Although I have workarounds, I am looking for best practices for this particular problem.</p>
  
  <pre><code>final class SportsMan {
  
      private final String name;
      private final int rank;
      private final String sport;
  
      public SportsMan (String name, int rank, String sport)  {
          this.name = name;
          this.rank = rank;
          this.sport = sport;
      }
  
      public String getName() {
          return name;
      }
  
      public int getRank() {
          return rank;
      }
  
      public String getSport() {
          return sport;
      }
  }
  
  
  final class Sport {
  
      private final String sport;
      private final int numberOfPlayers;
  
      public Sport(String sport, int numberOfPlayers) {
          this.sport = sport;
          this.numberOfPlayers = numberOfPlayers;
      }
  
      public String getSport()  {
          return sport;
      }
  
      public int getNumberOfPlayers() {
          return numberOfPlayers;
      }
  }
  
  
  public final class Joins {
  
      private Joins () {}
  
  
  
      public class SportsMenComparator implements Comparator&lt;SportsMan&gt; {
          @Override
          public int compare(SportsMan s1, SportsMan s2) {
              return s1.getSport().compareTo(s2.getSport());
          }
       }
  
  
  
      public static void innerJoinSort(List&lt;SportsMan&gt; sportsMans, List&lt;Sport&gt; sportList) {
          Collections.sort(sportsMans, new SportsMenComparator());
  
      }
  
  
  }
  </code></pre>
  
  <p>Eclipse results in the following message: <code>No enclosing instance of type Joins is accessible</code> where Joins is name of the enclosing class.</p>