title: Extending ArrayList and Creating new methods
body: <p>I'm having a bit of a problem grasping something - I might be going about this completely wrong.</p>
  
  <p>I am trying to create a class which extends ArrayList but has several methods which increase the functionality (at least for the program I am developing.)</p>
  
  <p>One of the methods is a findById(int id), which searches each ArrayList object for a particular id match. So far it's working, but it won't let me do <code>for (Item i : this) { i.getId(); }</code></p>
  
  <p>I don't understand why?</p>
  
  <p>Full code:</p>
  
  <pre><code>public class CustomArrayList&lt;Item&gt; extends ArrayList&lt;Item&gt; {
  
      // declare singleton instance
      protected static CustomArrayList instance;
  
      // private constructor
      private CustomArrayList(){
          // do nothing
      }
  
      // get instance of class - singleton
      public static CustomArrayList getInstance(){
          if (instance == null){
              instance = new CustomArrayList();
          }
          return instance;
      }
  
      public Item findById(int id){
          Item item = null;
          for (Item i : this) {
              if (i.getId() == id) {
                        // something
           }
          }
          return item;
      }
      public void printList(){
          String print = "";
          for (Item i : this) {
              print += i.toString() + "\n";
          }
          System.out.println(print);
      }
  }
  </code></pre>