JDK-4475301 : RFE: java.util.Stack.iterator() iterates the wrong way
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 1.3.1
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: generic
  • CPU: generic
  • Submitted: 2001-06-27
  • Updated: 2021-03-03
  • Resolved: 2001-11-14
Description

Name: bsC130419			Date: 06/27/2001


java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
Classic VM (build 1.3.0, J2RE 1.3.0 IBM build cx130-20001025 (JIT enabled: jitc))


The iterator method on java.util.Stack iterates through a Stack from the bottom
up. One would think that it should iterate as if it were popping off the top of
the Stack.

% cat test.java
import java.util.*;

class test {
    public static void main(String[] strs) {
        Stack s = new Stack();
        s.add("one");
        s.add("two");
        s.add("three");
        s.add("four");
        System.err.println(s);
        Iterator i = s.iterator();
        while(i.hasNext()) {
            System.err.println(i.next());
        }
    }
}
cindercone% javac test.java
cindercone% java test
[one, two, three, four]
one
two
three
four
% 

(Review ID: 127479) 
======================================================================

Comments
EVALUATION It was an incorrect design decision to have Stack extend Vector ("is-a" rather than "has-a"). We sympathize with the submitter but cannot fix this because of compatibility.
11-06-2004

WORK AROUND Name: bsC130419 Date: 06/27/2001 Create a StackIterator(Stack) which uses pop and push a lot to peer into the Stack. ======================================================================
11-06-2004