title: Generalized List as a parameter for a method
body: <p>Say I have a simple class like this:</p>
  
  <pre><code>public class BasicObject {
      private String name;
  
      public BasicObject (String str) {
          name = str;
      }
  
      public String getName () {
          return name;
      }
  }
  </code></pre>
  
  <p>then I have some simple method in the main class like this:</p>
  
  <pre><code>private static int findInList (____ list, String str) {
      for (int i = 0; i &lt; list.size(); i++) {
          if (list.get(i).getName().equalsIgnoreCase(str)) {
              return i;
          }
      }
  
      return -1;
  }
  </code></pre>
  
  <p>It would work if I put <code>List&lt;BasicObject&gt;</code> on the blank for the parameter <code>list</code>, but what if I have other objects? Can I generalize the list so this would work with other objects besides <code>BasicObject</code>? If so, how can I get the type of the objects in the list?</p>
  
  <p>Edit: What if I have another class from an imported package that I can still put in a list but I don't want to change what it implements? Is there a way to have a generalized <code>findInList</code> that includes those too? Or do I have to just make another method for that? I'm fine with just making another method, but I'm curious if this way is possible. </p>