previous | start | next

## Generic Methods

- Generic method = method with type parameter(s)

-     public class Utils
      {
         public static <E> void fill(ArrayList<E> a, E value, int count)
         {
            for (int i = 0; i < count; i++)
               a.add(value);
         }
      }

- A generic method in an ordinary (non-generic) class
- Type parameters are inferred in call

      ArrayList<String> ids = new ArrayList<String>();
      Utils.fill(ids, "default", 10); // calls Utils.<String>fill

previous | start | next