title: How to access the instance variable of an object stored in linkedlist collection?
body: <p>I am working on collections and generics. In my assignment, I have to store a person object into linked-list collection. Then I have to compare the age of person with value I given. But I am unable to access the variable of objects that stored in linked-list.</p>
  
  <p>Here is my code: </p>
  
  <pre><code>class person {
      int age;
      person(int a)
      {
         age = a;
      }
      public int getAge()
      {
           return age;
      }
  }
  
  class myList&lt;E&gt;
  {
    LinkedList&lt;E&gt; list;
    myList()
    {
      list = new LinkedList&lt;E&gt;();
    }
    void addElement(Person p){}
    void removeElement(int index){}
    boolean compareAge(int age){
         for(E p : list){
               int a = p.getAge();
               if(a.equals(age))
               {
                  return true;
               }
               else{
                  return false;
               }
         }
    }
  
  }
  </code></pre>
  
  <p>but, I am getting error that is :
  error: cannot find symbol
      p.getAge();
                                    ^
    symbol:   method get(int)
    location: variable value of type E
    where E is a type-variable:
      E extends Object declared in class myList</p>