title: Can't access the object within the GraphNode
body: <p>I have a graph that contains objects of type <code>GraphNodes</code>. These nodes contain an object <code>City</code> that has properties if It's infected or not. I want to loop through all the nodes and check if a city is infected or not. I have a generic method <code>getInfo</code> which returns an object of type <code>E</code> in my case <code>City</code>. But when i try to chain another method or to get property i can't see them as if they are not available. All the classes in the code are from college so i can't add/remove methods. I've tried with <code>foreach</code> but I still can't get the methods.</p>
  
  <p>Code:</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.InputStreamReader;
  import java.util.LinkedList;
  import java.util.Stack;
  import java.util.StringTokenizer;
  import java.util.LinkedList;
  
  class City {
  
      String osnovna_granka;
      boolean zarazen;
  
      City(String osnovna_granka, boolean zarazen) {
          this.osnovna_granka = osnovna_granka;
          this.zarazen = zarazen;
      }
  
      @Override
      public String toString() {
          if (zarazen == true) {
              return osnovna_granka + " zarazen";
          } else {
              return osnovna_granka + " nezarazen";
          }
      }
  }
  
  class Graph {
  
      int num_nodes;
      GraphNode&lt;City&gt; adjList[];
  
  
      @SuppressWarnings("unchecked")
      public Graph(int num_nodes) {
          this.num_nodes = num_nodes;
          adjList = (GraphNode&lt;City&gt;[]) new GraphNode[num_nodes];
      }
  
      int adjacent(int x, int y) {
          // proveruva dali ima vrska od jazelot so
          // indeks x do jazelot so indeks y
          return (adjList[x].containsNeighbor(adjList[y])) ? 1 : 0;
      }
  
      void addEdge(int x, int y) {
          // dodava vrska od jazelot so indeks x do jazelot so indeks y
          if (!adjList[x].containsNeighbor(adjList[y])) {
              adjList[x].addNeighbor(adjList[y]);
          }
      }
  
      void deleteEdge(int x, int y) {
          adjList[x].removeNeighbor(adjList[y]);
      }
  
      @Override
      public String toString() {
          String ret = new String();
          for (int i = 0; i &lt; this.num_nodes; i++) {
              ret += i + ": " + adjList[i] + "\n";
          }
          return ret;
      }
  }
  
  class GraphNode&lt;E&gt; {
  
      private int index;//index (reden broj) na temeto vo grafot
      private E info;
      private LinkedList&lt;GraphNode&lt;E&gt;&gt; neighbors;
  
      public GraphNode(int index, E info) {
          this.index = index;
          this.info = info;
          neighbors = new LinkedList&lt;GraphNode&lt;E&gt;&gt;();
      }
  
      boolean containsNeighbor(GraphNode&lt;E&gt; o) {
          return neighbors.contains(o);
      }
  
      void addNeighbor(GraphNode&lt;E&gt; o) {
          neighbors.add(o);
      }
  
      void removeNeighbor(GraphNode&lt;E&gt; o) {
          if (neighbors.contains(o)) {
              neighbors.remove(o);
          }
      }
  
      @Override
      public String toString() {
          String ret = "INFO:" + info + " SOSEDI:";
          for (int i = 0; i &lt; neighbors.size(); i++) {
              ret += neighbors.get(i).info + " ";
          }
          return ret;
  
      }
  
      @Override
      public boolean equals(Object obj) {
          @SuppressWarnings("unchecked")
          GraphNode&lt;E&gt; pom = (GraphNode&lt;E&gt;) obj;
          return (pom.info.equals(this.info));
      }
  
      public int getIndex() {
          return index;
      }
  
      public void setIndex(int index) {
          this.index = index;
      }
  
      public E getInfo() {
          return info;
      }
  
      public void setInfo(E info) {
          this.info = info;
      }
  
      public LinkedList&lt;GraphNode&lt;E&gt;&gt; getNeighbors() {
          return neighbors;
      }
  
      public void setNeighbors(LinkedList&lt;GraphNode&lt;E&gt;&gt; neighbors) {
          this.neighbors = neighbors;
      }
  }
  
  public class Main {
  
      public static void main(String[] args) throws Exception {
          int i, j, k;
  
          BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  
          int N = Integer.parseInt(br.readLine());
          Graph g = new Graph(N);
  
          for (i = 0; i &lt; N; i++) {
              StringTokenizer st = new StringTokenizer(br.readLine());
              st.nextToken();
              String osnovna_granka = st.nextToken();
              String str_zarazen = st.nextToken();
              if (str_zarazen.equals("zarazen")) {
                  g.adjList[i] = new GraphNode(i, new City(osnovna_granka, true));
              } else {
                  g.adjList[i] = new GraphNode(i, new City(osnovna_granka, false));
              }
  
          }
  
          int M = Integer.parseInt(br.readLine());
          for (i = 0; i &lt; M; i++) {
              StringTokenizer st = new StringTokenizer(br.readLine());
              int a = Integer.parseInt(st.nextToken());
              int b = Integer.parseInt(st.nextToken());
              g.addEdge(a, b);
              g.addEdge(b, a);
          }
  
          br.close();
          Stack&lt;GraphNode&gt; stack = new Stack&lt;&gt;();
          int counter = 0;
          // vasiot kod ovde;
          for(GraphNode gn: g.adjList) {
              gn.getInfo().// Here the properties of City should show up
          }
  
  
      }
  }
  </code></pre>