I am new to Generics in java and I really need help in this code
it is not compiling i dont know why!
The stack class is:
public class GenericStack<Item>{
public class Stack {
private Node first=null;
private class Node {
Item item;
Node next;
}
public boolean IsEmpty()
{
return first==null;
}
public void push (Item item)
{
Node oldfirst = first;
first = new Node();
first.item = item;
first.next = oldfirst;
}
public Item pop ()
{
Item item=first.item;
first=first.next;
return item;
}
}
}
and here is the main
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
GenericStack<Integer> ob = new GenericStack<Integer>();
ob.push(5);
obpush(10);
ob.push(15);
while (!ob.IsEmpty())
{
int x=ob.pop();
StdOut.print(x);
}
}
}
now the error is:
The method push(int) isn't defined for the type GenericStack<Integer>
Where did i go wrong?! can anyone explain please to me
Thank you in advance
GenericStackdoesn't have the methodpush, only the nested classStackhas it.