Why does the inner class complain about generic type?

Viewed 44

I have a class that implements Iterable so that the user can use an iterator. I'm using generics to allow the user to use any type and work with the class.

This is the working code below without warnings-

public class CustomStackUsingArray<Type> implements CustomList<Type>, Iterable<Type> {

    Type []arr;

    public Iterator<Type> iterator() {
        return (new ListIterator());
    }

    private class ListIterator implements Iterator<Type>{
        //Implement Iterator here
    }

    //Implement other methods here
}

However, if I have the ListIterator defined like this-

private class ListIterator<Type> implements Iterator<Type>

I get a warning in Eclipse, The parameter Type is hiding the type Type

Why does it complain when I specify the generic type after my class? Shouldn't I have to do that in order for me to be able to use Type inside my class? I added Type when defining CustomStackUsingArray and that works fine.

1 Answers
Related