Return Type is Incompatible when implementing iterator

时间:2016-04-04 16:57:06

标签: java

I am implementing iterator on a class and I keep getting the error for line 1 of the second part. It says that the return type is incompatible with iterator(). I know it has to do with the syntax of what I'm using since I'm new to coding.

import java.util.Random;
import java.util.NoSuchElementException;

public class Stack<Item> implements Iterable{
  private Item[] stack;
  private int size;
  private int N;

  public Stack(){
    stack = (Item[]) new Object[2];
    size = 0;
    N = 0;
  }

  public StackIterator<Item> iterator(){
    return new StackIterator<Item>();
  }

  public class StackIterator<Item> implements Iterator<Item>{

0 个答案:

没有答案