previous | start | next

## Anonymous Classes

- No need to name objects that are used only once

      Collections.sort(countries,

         new CountryComparatorByName());

- No need to name classes that are used only once

      Comparator comp = new

         Comparator()

         {

            public int compare(Object obj1, Object obj2)

            {

               Country country1 = (Country)obj1;

               Country country2 = (Country)obj2;

               return country1.getName().compareTo(country2.getName());

            }

         };

previous | start | next