Here is my code:
package datastructures; import java.util.Iterator; public class Stack{ private class Node{ T data; N
Node's data field doesn't know it's type.
Try giving the type when you initialize head.
private Node head; private Node newNode(T data){ Node new_node = new Node(); new_node.data = data; new_node.next = null; return new_node; }
Now, new_node knows that the data field is of type T.