私は Java の Generics が初めてで、このコードで本当に助けが必要です。コンパイルされていません。理由はわかりません。
スタック クラスは次のとおりです。
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;
}
}
}
そしてメインはこちら
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);
}
}
}
エラーは次のとおりです。
The method push(int) isn't defined for the type GenericStack<Integer>
どこで私は間違えましたか?!誰か説明してくれませんか
前もって感謝します