title: Java for-each loop says 'Incompatible Types' even though I am using generics
body: <p>I have a <code>Node</code> class that I am using for a directed graph in Java. The <code>Node</code> class is defined as so:</p>
  
  <pre><code>public class Node&lt;E&gt; {
      E val;
  
      public Node(E val) {
          this.val = val;
      }
  
      LinkedList&lt;Node&lt;E&gt;&gt; children = new LinkedList&lt;&gt;();
  }
  </code></pre>
  
  <p>In the same package, I have a static method in main that utilizes the <code>for-each</code> loop on the children member variable of a <code>Node</code> object.</p>
  
  <pre><code> static boolean processNode(LinkedList&lt;Node&gt; queue, HashSet&lt;Node&gt; visited, Node otherNode) {
          if (!queue.isEmpty()) {
              Node curr = queue.pop();
  
              if (curr.equals(otherNode) || visited.contains(curr)) {
                  return true;
              }
  
              visited.add(curr);
  
              for (Node child: curr.children) {
                  queue.add(child);
              }
          }
  
          return false;
      }
  </code></pre>
  
  <p>However, I get an error in the <code>for-each</code> loop: </p>
  
  <blockquote>
    <p>Error:(62, 34) java: incompatible types: java.lang.Object cannot be converted to TreesAndGraphs.Node
    Information:java: /home/tam/IdeaProjects/AlgorithmsPractice/src/TreesAndGraphs/RouteExists.java uses unchecked or unsafe operations.</p>
  </blockquote>
  
  <p>The children member variable is a <code>LinkedList</code> of <code>Node</code>s, so why is it expecting <code>Object</code> when I iterate over it?</p>