Re: iterator over superclass of collection
Frank Fredstone wrote:
Is there something, probably involving wildcards that would make it so
that I don't have to create an anonymous iterator class in my iterator
method of the iterable (where the iterable is of instances of
interfaces which are implemented by private classes).
You have received the same answer from several people. You might consider
accepting the advice.
The <? extends Aye> gives you the ability to directly use the collection's
iterator (Iterator<? extends Aye>) to manipulate instances of Aye that happen
to be PrivateAye, but no one using the Iterator can know that. The behavior
of each object accessed via the Iterator will be PrivateAye's behavior, as my
SSCCE upthread shows you, but the access will only be through a variable of
What of that fails to achieve what you want?
What I need PrivateAye for is to demonstrate a scenario where I need
to have an iterable of interfaces where the actual implementation is
Does that, assuming by "private" you mean "not displayed to clients of the
I don't have to create an anonymous iterator class in my iterator
method of the iterable
Check. Just use the iterator of the collection directly, no anonymous
In the collection class I want to have a private implementation of
I was hoping that I had missed some typical way, using wildcards, to get
Iterator<Aye> in my super-class of Iterable<Aye> from my backing
collection of PrivateAye objects, instead of having to write a special
case Iterator class to instantiate in the iterator method.
If you use Iterator<? extends Aye>, you get instances of Aye from the Iterator
that behave like PrivateAye, just like you want, without writing a special
Iterator class, just like you wanted.
I'm sorry, but I just don't see anything missing from what several people are
telling you. Why not try it?