United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4475301 : RFE: java.util.Stack.iterator() iterates the wrong way

Details
Type:
Enhancement
Submit Date:
2001-06-27
Status:
Closed
Updated Date:
2001-11-14
Project Name:
JDK
Resolved Date:
2001-11-14
Component:
core-libs
OS:
generic
Sub-Component:
java.util
CPU:
generic
Priority:
P4
Resolution:
Won't Fix
Affected Versions:
1.3.1
Fixed Versions:

Related Reports

Sub Tasks

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
WORK AROUND



Name: bsC130419			Date: 06/27/2001


Create a StackIterator(Stack) which uses pop and push a lot to peer into the Stack.
======================================================================
                                     
2004-06-11
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.
                                     
2004-06-11



Hardware and Software, Engineered to Work Together