I have suddenly forgotten how method calls inside if-checks works.
Example:
if (list.next() instanceof AClass) {
AClass thing = list.next();
}
If list
is an Iterator, you may need something like:
AClass thing = null;
Object n = list.next();
if (n instanceof AClass) {
thing = (AClass) n;
}
in order to call .next()
just once. Two subsequent calls will return two objects, because internal position is moved one step forward on each .next()
invocation. There no any kind of "reversion" occurs.