previous | start | next

## Anonymous Classes

- Commonly used in factory methods:

      public static Comparator<Country> comparatorByName()
      {
         return new Comparator<Country>()
         {
            public int compare(Country country1, Country country2)

            { . . . }
         };
      }

- `Collections.sort(a, Country.comparatorByName());`
- Neat arrangement if multiple comparators make sense
  (by name, by area, ...)

previous | start | next